0

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

1 Answers1

1

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
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
  • Math.Atan2 is described here: [link](https://stackoverflow.com/questions/12891516/math-calculation-to-retrieve-angle-between-two-points) – Metoděj Svoboda Feb 07 '22 at 18:24