This is an archive of G2M. Please refer to this post for more information. Archived on 2026-01-09.

Generating heading from current point and end point

totesnotrosalyn
09/25/2024 at 06:39:36 AM PDT

I can’t seem to figure out the math to generate a heading from a start and end point. Any help?

iseau395
09/25/2024 at 02:09:21 PM PDT

You can use the atan2 function to get the angle from one point to another

in_ithaca
09/27/2024 at 09:44:01 PM PDT

the atan2 function calculates the arc tangent and adds some angle values depending on the sign of the change in x and change in y. tan(angle) = y/x so atan(y/x) = angle.

J.4
09/29/2024 at 09:29:17 PM PDT

Here’s a desmos interactive I made that you can use. The main arctangent function is on the left-hand sidemenu. Rendering functions were put in the “other stuff for rendering” folder. You can drag the blue and red points.