Converting a 2D polygon with 4 sides into a circular graph

Crabbers

New member
Joined
Jul 24, 2020
Messages
6
I’m trying to help a friend resolve a plotting issue.

He has 4 bits of data with values 0-100 which are plotted on a graph (to make it slightly harder he’s using 45,135,225 and 315 axis) the resultant is a 4 sided polygon, so far so good, but he wants the output to be shown on a circular plot.

Now if all 4 bits of data are 100 the resultant shape is a square where each point rests on the circumference of a circle radius 50. There are then areas in each quadrant which are not plotted despite a max score in the adjacent plots. So the straight line between 2 plots needs to be “stretched” into a curve.

As the maximum error occurs at 0,90,180,270 (remembering he’s plotting on the diagonals) then my idea would be to increase the values of each point along the line by a value which compensates for the circle. Something like x=cos(2.angle) where x is the addition to the y co-ordinate of the line. Does that make sense ? It’s at a maximum at 0 degrees (North) then is 0 at 45 where the square touches the circle.

But how do you calculate the values of each point on the line? It’s ok if it’s a square (where each score is 100%) but what if it’s a polygon with no right angles?
 
I don't fully understand the problem. Are you after a result that might look something like this?

sketch.png
ABCD represent the data points, and their distance from the origin is determined by the 4 data values. And do you require a curve to flow between them, such that if A=B=C=D the blue curve would appear circular?

If I'm barking up the wrong tree, then please provide a quick sketch (hand drawn, and take a photo would be fine).
 
Something like x=cos(2.angle) where x is the addition to the y co-ordinate of the line. Does that make sense ? It’s at a maximum at 0 degrees (North) then is 0 at 45 where the square touches the circle.

I can see what you're thinking. If you are working in polar coordinates, then I'd recommend that you partition your function into 4 (so there would be 4 expressions).

For the section from B to A, then θ would have the following domain of values -π/4 ≤ θ < π/4 (working in radians). Can you write an equation for r in this domain, I'll start you off...

r(θ) = B + (A−B)*(0.5 + 0.5*cos( <something> ))

You'll want the value returned from cos to go from -1 when θ=-π/4, up to 1 when θ=π/4
 
Last edited:
What I really need I guess is given 4 values to represent a,b,c & d as co-ordinates (45,a) (135,b) (225,c) (315,d) where each value is 0-100 how can I draw the blue circle you have above?
 
What I really need I guess is given 4 values to represent a,b,c & d as co-ordinates (45,a) (135,b) (225,c) (315,d) where each value is 0-100 how can I draw the blue circle you have above?

I think I understand the requirement. But I have one question, would the angles ever change or will they always be set at 45, 135, 225, 315?

On this site we prefer to give hints to help you solve the problem yourself. That way you'll learn more! There are many ways that a pleasing curve passing through the points could be generated. In post #4 I was suggesting quite an easy way (and you seemed to be suggesting the use of "cos" yourself). Is there anything in particular about post#4 that you don't understand? Do you know how to generate a plot in polar coordinates? I assume you want to plot this on a computer? Would you want to use a plotting tool, like "Desmos" for example? Have you heard of splitting a function? I was recommending that you try splitting the function into 4, dealing with domains B to A, A to D, D to C, and C to B as 4 separate expressions.
 
Hi Cubist, in answer to your question, yes the coordinates will always be set at 45 deg etc. I’ve been on a night shift so haven’t had time to look closer yet, I went to school so long ago that Pythagoras hadn’t yet been born! I can’t remember doing polar coordinates or rad. However I’m quite enjoying the mental stretch.

Yes I am hoping to come up with some way of including the plot in a web page, my friend uses a series of questions to determine a personality type, which he does by hand and plots the resultant of the 4 on a polar chart as a single point. Which translates toward a set of behaviours. He’s 78 and it’s getting a bit much so I’m trying to help him make it all web based (the questions are) and it would be nice given he knows the 4 coordinates to be able to superimpose them on top in a circular form. He’s using 45/135/225/315 as the central axis of each main personality profile with 24 types in all each with a 15deg arc (or Pi/12 rads, see I’m slowly getting there, I think).
 
Is the something cos(x-pi/6) Which multiplied by A or B gives their polar coordinate?

Bit confused as to whether I should be working in radians, degrees or (x,y) or the polar equivalent.
 
I went to school so long ago that Pythagoras hadn’t yet been born!
?

Bit confused as to whether I should be working in radians, degrees or (x,y) or the polar equivalent.
Most computer languages use radians for the trig functions sin and cos, but it is easy enough to convert degrees to radians (multiply by pi and divide by 180)

Yes I am hoping to come up with some way of including the plot in a web page

How are you thinking of generating the graph, perhaps:-
- a CGI script (running on a webserver)
- javascript (running on a client's computer)
- something else

OK, I've made a graph using the idea from post#4, you can move the sliders A to D to see the effect. Click here for the Desmos graph. The result is not as nice as I was hoping for. When a number becomes small then the curve becomes a bit too pointy (in my opinion anyway). But its a good first try and maybe I (or someone else) will have a better idea.
 
Thanks for that, I haven’t yet decided how to script it but I’m open to ideas. At the moment his business is dead in the water with COVID and moving it entirely online is a matter of urgency.
 
Top