Can someone explain this to me in plain english?
I've attempted to draw a line at a specific angle (180 to -180) and while I got it to work, I had to snipe some of the code from somewhere else, and I'd like to understand it.
My math skills aren't very good. If I were to pit myself against a garden hose in a math battle, I wouldn't bet on myself.
Anyways, here's the formula...
-> Piece 1 "Doing stuff to the angle":
angleConverted = 2.0 * pi * angleIncoming / 360;
'angleIncoming' is the human angle you input, ie. 45.
Now, I'm not really sure what angleConverted is. I'm assuming it's some type of radians to degrees formula because later on in the formula I have to Sin()/Cos() this angle to draw the actual line and they work off radians, but *** is the 2.0?
-> Piece 2 "Setting up the point to draw":
Point degreesPoint = new Point(Convert.ToInt32(picWidth * Math.Sin(angleConverted)), Convert.ToInt32(picHeight * Math.Cos(angleConverted)));
I'd like to keep this language neutral, so I'll explain what's going on here. Basically I'm making a new point, and initializing the X/Y coords.
The X coord is set to the width of the picture box I'm drawing it on * the sine of the angleConverted. The Y coord is the same deal, except I'm using the height of the picture box and Cos'ing the angleConverted.
The Convert.ToInt32() piece is necessary because the Sin/Cos functions return a double not Int, and the point coords are stored as Int, not double. Hence the convert!
So yeah...can someone explain both pieces to me so they make sense? At a later time I would like to reverse engineer the formula, so I can convert the mouse coords into a degree (so the user can drag the line, and it would spit out the degrees in addition to draw the line in real time).
Re: Can someone explain this to me in plain english?
Quote:
Now, I'm not really sure what angleConverted is. I'm assuming it's some type of radians to degrees formula
It is the other way around, angleConverted is in radians, the formula for conversian between degrees/radians is:
degrees / 360 = radians / 2pi
or equivalently:
radians = 2pi * degrees / 360
All points on a circle have the same distance, r to the center. You can form a triangle between the center, a point on the circumference of the circle and the x axis. Using the rules that:
1) The sine of an angle is the ratio of the length of the opposite side to the length of the hypotenuse.
2) The cosine of an angle is the ratio of the length of the adjacent side to the length of the hypotenuse.
We get that the x coordinate is cos(angle)*r, and the y coordinate is sin(angle) * r.
In your code these are reversed, the effect is that angle 0 is to the bottom, instead of to the right.
If you use different radii in the x and y direction you will get a point on some kind of ellipse.