1

I am currently coding a program that draws a race track by combining multiple line segments that the user defines (which can be either a straight or a curve).

For my curve, I have the data for its radius, length and starting point. Using some maths explained here, I can also calculate the end point coordinates.

What would be a way to calculate the endpoint angle of the arc? It is important for me to know the end angle as the next line segment that connects with the arc will start with the same angle as the arc.

enter image description here Example track Diagram

Edit

enter image description here Problem Diagram

I am interested in finding the angle that a tangent intersecting the end point would make with the x axis.

David K
  • 98,388
ps1234
  • 13
  • Do you know the coordinates of the center of the arc? – David K Jan 25 '21 at 04:23
  • No I don't know the coordinates of the center. I was thinking if needed, I can find the center by constructing a chord between the two points and then using some trigonometry. – ps1234 Jan 25 '21 at 05:05
  • I came across this link - (https://stackoverflow.com/questions/57769249/how-to-calculate-start-end-angle-of-an-arc-by-given-2-points). Say the arc has center at C and end points at S and E. In they link, someone suggested using the atan2 (https://en.wikipedia.org/wiki/Atan2) formula to find the angle between the x axis and the vector CE (say alpha). Since we know that the tangent at the end point E would be perpendicular to the line CE, wouldn't the angle between x-axis and the tangent just be alpha + 90*? – ps1234 Jan 25 '21 at 05:20
  • I would double-check your endpoint calculations, since the question you got them from had insufficient information. There are infinitely many arcs with the same radius, arc length, and starting point, depending on your starting direction and also on whether it is a right or left turn. Note that the ending direction is just the starting direction plus or minus the angle by which you turn. – David K Jan 25 '21 at 13:42

2 Answers2

1

The angle an arc spans (in radians) is $$ \widehat{\rm angle} = \frac{\rm arclength}{\rm radius} $$

Then you simply add up all the angles of all the corners up to the one you are drawing to find where the orientation of the arc end.

When the final orientation is 360° you have completed one circuit of the track.


The more interesting problem is coming up with the arc endpoint coordinates from the standpoint coordinates $(x_1,\,y_1)$, the initial direction $\theta_1$, the radius $r$ and the arc length $s$.

fig1

  1. A counter clockwise arc sweeps an angle $\varphi = s/r$ in radians, so the final direction of the track after the arc is $\theta_2 = \theta_1 + \varphi$.

    The endpoint coordinates are found with some trigonometry

    $$ \pmatrix{x_2 \\ y_2} = \pmatrix{x_1 -r \sin \theta_1 + r \sin \theta_2 \\ y_1 + r \cos \theta_1 - r \cos \theta_2 } $$

  2. A clockwise arc sweeps an angle $\varphi = s/r$ in radians, so the final direction of the track after the arc is $\theta_2 = \theta_1 - \varphi$.

    The endpoint coordinates are found with some trigonometry

    $$ \pmatrix{x_2 \\ y_2} = \pmatrix{x_1 +r \sin \theta_1 - r \sin \theta_2 \\ y_1 - r \cos \theta_1 + r \cos \theta_2 } $$

John Alexiou
  • 13,816
  • Thank you so much for the answer!!!. My endpoint calculation was also off and you've cleared that doubt as well. – ps1234 Jan 27 '21 at 09:15
  • What was your calculation to get the endpoint? Instead of turning left, you can also have an arc that turns right. The final angle would just be theta1 - alpha1. How would you calculate the endpoint then? – ps1234 Jan 28 '21 at 00:10
  • Flip the sign of $r$ in the formula above, as well as use $\theta_2 = \theta_1 - \varphi$ – John Alexiou Jan 28 '21 at 00:46
  • Thank you for that. – ps1234 Jan 28 '21 at 03:28
  • Sorry for the stupid question, but if the theta1 is negative, would that skew the result? Asking because while testing, I started with a straight (length: 50, angle: 0, calculated endpoint: (50, 0)) to the right, then right (length: 100, radius: 10, calculated endPoint: (x: 44.559, y: -18.39)) and finally left (length: 100, radius: 10, calculated endpoint: (39.11, -36.78)). I expected the final endpoint to be (50, 0) as you go first right, then left with the same length and radius. Is this because of the fact that the start angle was negative? – ps1234 Jan 28 '21 at 06:34
  • length 100 and radius 10 = angle of 10 radians = 572.96°. That is > 1 full circle?? – John Alexiou Jan 29 '21 at 02:25
  • You can confirm the equations with this CAD sketch of a track segment. – John Alexiou Jan 29 '21 at 02:31
  • Yep the CAD clears all the doubts. – ps1234 Jan 29 '21 at 02:41
  • @ps1234 I used DesignSpark Mechanical a free direct modeler derived from SpaceClaim. – John Alexiou Jan 29 '21 at 13:33
  • Ahh right. Cheers for letting me know. – ps1234 Jan 29 '21 at 16:45
0

Edit: Let $r$ be the (known) radius and $M$ the midpoint of $SE$ ($S$, starting point; $E$, endpoint).

Angle $\alpha$ (see figure) is such that

$$\cos \alpha =\dfrac{SM}{SC}=\dfrac{SE}{2r} \ \iff \ \alpha=\operatorname{acos}(\dfrac{SE}{2r})$$

with

$$SE=\sqrt{(x_e-x_s)^2+(y_e-y_s)^2}$$

using coordinates $S=(x_s,y_s)$ and $E=(x_e,y_e),$.

enter image description here

Jean Marie
  • 81,803
  • Hey thanks for you reply. Sorry for not being more clear. All the things i mentioned about track was to just give a bit of context on what I was doing. What I really wanted to know was, say you have an arc with a certain radius, arc length and you also have the coordinates for its start point (where the arc starts) and end point (where the arc ends). Given all this data, is there a way to find what would be the angle at which the arc ends? In other words, if a tangent intersects the arc at the end point, what would its angle be? – ps1234 Jan 23 '21 at 04:26
  • I have adapted my answer. Is it what you are waiting for ? – Jean Marie Jan 23 '21 at 10:41
  • So in your calculation, you calculated the angle between SC and SE. What I wanted was the angle it made with the x-axis. I have added a diagram in the post above. I am not sure if that is possible as I don't have the gradient of the tangent. – ps1234 Jan 25 '21 at 04:07