简体   繁体   中英

Graph Visualization Represented in a Circle: How To

Graph Visualization represented in a Circle: How To

I am trying to represent a plotted graph line around a circle.

  1. Where the center is 0
  2. Intervals of 45 degrees / 8 values.
  3. Greatest value = 1 / outer boundary of circle.
  4. I want to plot the graph at each interval
  5. Points at right angles are straight forward

I could hack this pretty easy but I'd rather know the math in case I ever want to do more complex things.

I am looking for the math to figure out where the 45 degree increments should be. For example: if the point is .33 of 1 then how do I know where it will be at 45 degrees or at 13 degrees, etc. etc.

Why Lua? I'm coding in lua so that would be the perferable

EDIT: Made a picture but I don't have enough rep :(

Bar 1 @ 0 Deg   = Lenght of 1    = x,y of  0,1 
Bar 2 @ 45 Deg  = Lenght of .33  = x,y of  ?,?
Bar 3 @ 90 Deg  = Lenght of .5   = x,y of .5,0
Bar 4 @ 105 Deg = Lenght of .66  = x,y of  ?,?

How do I get the x,y of Bar 2 and Bar 4?

The easiest way is with polar coordinates where:

x = r cos φ and y = r sin φ

( r would be your length and φ would be your angle)

The one wrinkle is that in polar coordinates, φ = 0 is along the positive x-axis and increasing angles rotate counter-clockwise. To account for the offset in 0° we just subtract 90° from your desired angle. Then to change the rotation to clockwise, we just take the negative of the result. So,

phi = -(angle - 90)
x = length * cos(phi)
y = length * sin(phi)

For your current problem with only 8 angles you could calculate these by hand pretty readily knowing that both cos and sin of 45° is about 0.707.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM