Graph Visualization Represented in a Circle: How To - math

Graph Visualization represented in a Circle: How To
I am trying to represent a plotted graph line around a circle.
Where the center is 0
Intervals of 45 degrees / 8 values.
Greatest value = 1 / outer boundary of circle.
I want to plot the graph at each interval
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.

Related

How to calculate coordinates X and Y of a ellipse with angle

An image says more than words.
How to calculate the X and Y.
It is not an ellipse strictly, but a circle.
The parametric equation of circle is given by (r cos t, r sin t), where r is the radius of the circle & t is the respective angle subtended by the point at the center of circle whose centre lies at origin.
x = r cos (t), y = r sin (t).
So, in your case the nature of the circle is center at 250,250 and radius = 250.
Therefore, equation of circle => (x - 250)^2 + (y - 250)^2 = 250^2.
Now, substitute t = 310 degree(we need to calculate the angle in anti-clockwise(counter-clockwise) direction, so t = 270 + 40 = 310 degrees, since y is in the downward direction, that too in the fourth quadrant with respect to circle) in the given equation and its parametric coordinate as x = 250 + r cos (t) ,and y = 250 + r sin (t) to calculate the values of x and y respectively.
Thanks to LutzL for clarifying OP's figure.

plot plane using 3 points in scilab

I have three points a,b,c whose x,y,z coordinates are
a=[ -0.3519052 0 0];
b=[ 0 -0.674984 0];
c=[ 0 0 -0.6485047];
how do plot a plane(triangle) using these three points in scilab
plot3d and plo3d1 are not giving the form i am looking for.
I figured out the problem!
plot3d1 needs column vectors.
plot3d1(a',b',c')
produced the plot
how to plot triangle in scilab
Plot a triangle using its sides
Consider the fist vertex lies at origin(0,0)
Second vertex lies on X-Axis at (a,0)
From distance formula of triangle
ie.
length of side = sqrt( (x2−x1)^2+(y2−y1)^2 )
Program to Plot a Triangle when sides are given is as below in scilab :
clf()
//Length of the sides
a = 10;
b = 10
c = 10
//Vertex of third point
xc=(a^2-(b^2-c^2))/(2*a)
yc=sqrt(c^2-xc^2);
clf()
x=[0,0,xc]
y=[0,yc,0]
plot2d(0,0,-1,"010","",[0,0,0,0]);
xpoly(x,y,"lines",1)

Set vector2 coordinates by move distance and degree

I have a Vector2 in my 2D Game and what I would like to do now is set my vector2 x and y by calculating them using rotation in degrees
Do I need to use PI to calculate new X and Y coordinates then add move distance per second in order to get the correct coordinates?
Example : Lets say degree is 90, which means my gameobject would move forward,at 5 floating units per second, then Y would be 5,10,15 and if degree would be 180 then X would increase by 5 every second, this is simple, but how to do it for other degrees such as 38,268 etc?
The usual convention is that 0 degrees points in the positive X direction and as the angle increases you rotate the direction anti-clockwise. Your convention seems to be that 0 degrees points in the negative X direction and the angle increases clockwise, so first of all you must translate your angle, say alpha, into one with the usual convention, say beta
beta = 180.0 - alpha
Next, trigonometric functions assume radians which run from 0 to 2π rather than from 0 to 360, so you must translate beta into an angle in radians, say theta
theta = 2.0*PI*beta/360.0
Finally, cos(theta) gives the change in X for a move of 1 unit in the direction given by theta and sin(theta) gives the change in Y. So you need
X = X + D * cos(theta)
Y = Y + D * sintheta)
for a distance D. Using your convention this translates to
X = X + D * cos(2.0*PI*(180.0-alpha)/360.0)
Y = Y + D * sin(2.0*PI*(180.0-alpha)/360.0)

polygon coordinates

how can we draw a polygon. when only the sides and radius is given.
I have to make a pop up box which will take as input the radius and number of sides and will draw a ploygon. just need the formula.
Imagine a circle of radius r. It is like a regular polygon with an infinite number of sides.
Trigonometry tells us:
x = r * cos(a);
y = r * sin(a);
We know there are 360 degrees or 2pi radians in a circle. So to draw it we would start with angle = 0, calculate that co-ord, step to the next angle and calculate that point, then draw a line between the two.
There are only so many points we can calculate around the edge of the circle, eventually it won't make any difference. If the circle is small enough, even 8 sides will look round.
To draw an 8 sided circle we want 8 points evenly spaced around the circle. Divide the circle into 8 angles, each one is 2 * pi / 8 radians.
So:
angle = 0.0;
step = 2 * pi / 8;
for ( n = 0; n < 8; n++ ) {
x = radius * cos(angle);
y = radius * sin(angle);
angle += step;
}
Now you can draw an octagon, change it to draw the general case.

finding a dot on a circle by degree?

Let's say we have a 100x100 coordinate system, like the one below. 0,0 is its left-top corner, 50,50 is its center point, 100,100 is its bottom right corner, etc.
Now we need to draw a line from the center outwards. We know the angle of the line, but need to calculate the coordinates of its end point. What do you think would be the best way to do it?
For example, if the angle of the line is 45 degrees, its end point coordinates would be roughly 75,15.
You need to use the trigonometric functions sin and cos.
Something like this:
theta = 45
// theta = pi * theta / 180 // convert to radians.
radius = 50
centerX = 50
centerY = 50
p.x = centerX + radius * cos(theta)
p.y = centerY - radius * sin(theta)
Keep in mind that most implementations assume that you're working with radians and have positive y pointing upwards.
Use the unit circle to calculate X and Y, but because your radius is 50, multiply by 50
http://en.wikipedia.org/wiki/Unit_circle
Add the offset (50,50) and bob's your uncle
X = 50 + (cos(45) * 50) ~ 85,36
Y = 50 - (sin(45) * 50) ~ 14,65
The above happens to be 45 degrees.
EDIT: just saw the Y axis is inverted
First you would want to calculate the X and Y coordinates as if the circle were the unit circle (radius 1). The X coordinate of a given angle is given by cos(angle), and the Y coordinate is given by sin(angle). Most implementations of sin and cos take their inputs in radians, so a conversion is necessary (1 degree = 0.0174532925 radians). Now, since your coordinate system is not in fact the unit circle, you need to multiply the resultant values by the radius of your circle. In this given instance, you would multiply by 50, since your circle extends 50 units in each direction. Finally, using a unit circle coorindate system assumes your circle is centered at the origin (0,0). To account for this, add (or subtract) the offset of your center from your calculated X and Y coordinates. In your scenario, the offset from (0,0) is 50 in the positive X direction, and 50 in the negative Y direction.
For example:
cos(45) = x ~= .707
sin(45) = y ~= .707
.707*50 = 35.35
35.35+50 = 85.35
abs(35.35-50) = 14.65
Thus the coordinates of the ending segment would be (85.35, 14.65).
Note, there is probably a built-in degrees-to-radians function in your language of choice, I provided the unit conversion for reference.
edit: oops, used degrees at first

Resources