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

Get the angle and the distance of point from center point

I’m trying to make a color picker and need some help, I need to get an angle of a point from a center point, starting from the top moving to the left, highest value being 1 and the lowest 0, as well as distance between the two points;

I skipped math in high school so I’m at a loss, any help would be appreciated

enter image description here

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 :

to find angle between center and the point in radians:
Math.Atan2(point.y-center.y,point.x-center.x)
normalize it:
Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2
make it start from top:
Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2+0.25
don’t let it go below zero:
(Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2+0.25+1)%1
invert it so it goes counterclockwise:
1-(Math.Atan2(point.y-center.y,point.x-center.x)/Math.PI/2+0.25+1)%1

you can rewrite it as:
1-(Math.Atan2(point.y-center.y,point.x-center.x)/2/Math.PI+1.25)%1

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