Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Best way to find the angle between two grids?

If I have a lattice graph which looks like this:

0:0 0:1 0:2 0:3
1:0 1:1 1:2 1:3
2:0 2:1 2:2 2:3
3:0 3:1 3:2 3:3

, what is the best way to find an angle between two nodes?
Example:

angle(0:0, 0:1) = 0;
angle(0:0, 1:1) = 45;

This will be used during rendering to visualize a path in this graph with lines, a line will be placed at the center of a node and then rotated to end in the next node on the path. Currently I hardcoded every coordinateS difference and match it to the corresponding angle with a switch statement, are there better ways?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming x:y format, and an angle measured clockwise from the horizontal:

angle(x1:y1, x2:y2) = arctan((x2-x1)/(y2-y1))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading