简体   繁体   中英

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

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM