0

I am a programmer but my maths skills are poor, I find geometry, trigonometry and algebra etc. difficult to grasp. But I have had a look online for the solution to this problem to no avail, I hope someone can help.

I have an elliptical arc into which I am drawing line segments, however on occasion I need to draw arcs that follow the curve of the arc between the line segments, please see the blue lines in the picture:an arc intersected by 3 line segments from below

Is there a formula that I can use that will tell me the degree positions where these blue arc sections should start and end. I know the x position of the line segments (and the two radii of the ellipse and the start and end x position of the ellipse)?

  • It depends on how your software uses "degree positions" to decide how to draw the ellipse. If the ellipse is made by stretching or shrinking a circle by different amounts in the vertical and horizontal directions, and the angles describe the arc on the circle before the stretching/shrinking, you get a different answer than if the angles are measured on the final ellipse. You also need to know which point of the ellipse is at the "zero" angle. This can be worked out by repeated trial and error, or you can read the documentation. Perhaps this is really a SO question? – David K Mar 12 '17 at 17:22
  • @DavidK I don't know about the first part but the zero angle is from the centre to the right. – Tim the Enchanter Mar 12 '17 at 17:28

1 Answers1

1

I will make a guess that the graphics program renders an ellipse by stretching or shrinking a circle by different amounts in the horizontal and vertical directions, and that the angles that determine the start and end of each arc are measured on the circle before it is stretched/shrunk. That is, the direct input to the graphics function uses angles like the angle named $\theta$ in Figure 14 on this page to decide where to start or stop an arc.

I also assume that the green arc represents an arc from $0$ degrees (at the right end) to $180$ degrees (at the left end), and that the horizontal coordinates of points are increasing as we go to the right.

Let the horizontal radius of the ellipse be $a$ and let the center of the ellipse have horizontal coordinate $x_C.$ For a vertical line at horizontal coordinate $x_1,$ let $$ \theta = \arccos\left(\frac{x_1 - x_C}{a} \right), $$ where $\arccos(\cdot)$ is the inverse cosine function. Then $\theta$ is the angle that the graphics function takes to describe the point where the vertical line meets the ellipse.

Note that in many (if not all) math libraries that have an inverse cosine function, the output of the function is in radians rather than degrees. If you really need degrees for your graphics input, you may need to multiply by $\frac{180}{\pi} \approx 57.2957795131.$

In case you do not have an inverse cosine function, there are workarounds that use either the inverse tangent function or inverse sine function, but this problem becomes a lot more difficult if you have no access to any inverse trigonometric functions.

David K
  • 98,388
  • I found this http://math.stackexchange.com/questions/370013/determine-the-angle-of-an-point-in-an-ellipse which talks about arctan. Is that in answer to the same question as I gave? – Tim the Enchanter Mar 12 '17 at 22:09
  • @TimtheEnchanter The answer to that question assumes you know the exact coordinates ($x$ and $y$) where the arc starts or ends. You can get those coordinates from the information you have, which is one of the "workarounds" I might suggest you use if there is no inverse cosine available. But the question with the information you gave is easier to answer with inverse cosine than arctan. The inverse cosine is usually named acos, inverse tangent is usually atan or atan2. – David K Mar 12 '17 at 22:57
  • Thank you, I really wish I understood this better. – Tim the Enchanter Mar 12 '17 at 23:30