Oren Trutner
2009-08-20 22:25:33
views:
1018answers:
1Cool! That works. But I still don't understand why it works. What is the logic behind your calculation? Does this have anything to do with polar vs. Cartesian coordinates?
jameswelle
2009-08-21 04:18:43
GetPointOnEllipse finds a point in two steps:1. it finds a point on the circumference of a circle with R=1 at an angle A from the X axis, at (cos(A), sin(A))2. it transforms the point with a stretch transform, to (w*cos(A), h*sin(A))The stretch transform changes the angle! (imagine what the angle would be if we stretched the circle very wide)To find the new angle B, note that tan(B)=y/x, and hence B=atan(y/x). To avoid dividing by zero, we'll use B=atan2(y,x)As (x,y)=(w*cos(A), h*sin(A)), we get B=atan2(h*sin(A),w*cos(A))Divide by w to get B=atan2(sin(A)*h/w,cos(A))Makes sense?
Oren Trutner
2009-08-21 05:50:47
I don't fully understand your statement: "The stretch transform changes the angle!". I can see from the output image that the angle is different. But what I am confused on is the formula for a point on an ellipse. The formula is x = a cos(theta), y = b sin(theta). Does the fact that it draws at a different point mean that the angle being measured is different from the angle being measured by AddArc? I found another thread on this subject. It seems to point to the issue having something to do with polar coords. http://bytes.com/topic/c-sharp/answers/665773-drawarc-ellipse-geometry-repost
jameswelle
2009-08-22 05:01:08
If we draw a line inclined at 45 degrees to the X axis, then for each point on that line, x=y, always, at all times -- wouldn't you say? We could draw that line on the screen, or on paper. What about theta=45, however? We know sin(45)=cos(45)=~0.707. For our ellipse, a cos(45)=b sin(45) if and only if a=b. If a>b then x>y, and therefore won't touch the 45 degrees line on the screen/paper. It's located somewhere to its right. That means that theta does not track the angle you are looking for on the screen. It's confusing because theta ranges between 0 and 360 like a circle (contd.)
Oren Trutner
2009-08-22 06:58:51
(contd.) It's also confusing as theta IS the correct angle for precisely 4 points on the ellipse -- when the ellipse crosses the X and Y axes. But at all other points on the ellipse, theta is not the correct angle. AddArc does the right thing. When you tell it to end at 45 degrees, it precisely hits the 45 degrees line we drew. It ignores the fact that the arc is on the surface of an ellipse that can be described by a cos(theta),b sin(theta), or by any other formula for that matter.
Oren Trutner
2009-08-22 07:03:42
I agree that AddArc is doing the right thing. Which leads me to believe that theta in the ellipse equation is not an angle measured from the center of the ellipse, or it would come up with the same point, correct? So what is theta in the ellipse equation?
jameswelle
2009-08-22 20:13:02
Exactly -- that is correct. As for theta, you could say that it tracks the angle on a circle that is 3d-projected to the ellipse using orthographic projection.
Oren Trutner
2009-09-03 23:34:27
+1 for being unlike the vast majority of random math-challenged folks and not only being able to do basic math but hitting geometry home runs with ease!
Emtucifor
2010-08-09 22:44:39