Discussion Forum: Off Topic: Message 1389985
 Previous Message   Next Message 
 Author: chetzler View Messages Posted By chetzler
 Posted: Jan 27, 2023 21:52
 Subject: Re: Complicated Mathematics
 Viewed: 42 times
 Topic: Off Topic
Cancel Message
Cancel
Reply to Message
Reply
BrickLink
ID Card

chetzler (2342)

Location:  USA, Minnesota
Member Since Contact Type Status
Feb 12, 2005 Contact Member Seller
Buying Privileges - OKSelling Privileges - OK
Store: Lost Boys' Brick Shop
In Off Topic, Fr0stByt3 writes:
  I have gone around and around with this problem for a while now.

Let's say there is a circle divided into eight sectors, with sector one being
from degrees zero to forty-five, sector two being from degrees forty-five to
ninety, and so on. Let's say a point is plotted somewhere randomly on the
circle. How would you determine which sector that point is in?

The reason I ask this question is because I have a perfectly round user interface
and I need to perform some action depending on which sector was clicked.

My thoughts so far are to somehow draw an imaginary line between the point clicked
and the origin of the circle, draw an imaginary line from the origin straight
up the screen, and get the angle between those two lines clockwise. If it's
between (i - 1) * 45 and i * 45 degrees, then it's in the ith sector. I would
not know how to program this without a formula; believe me, I tried.

Reference:

Assuming you have x and y coordinates with (0,0) being the center of your circle,
convert them to polar form (r,θ):

r = sqrt(x^2 + y^2)

θ = arctan(y/x) ... or atan(y/x) depending on the language.

All you really need though is θ, the angle. The arctan function will probably
return θ in radians so you would need to multiply by 180/π to convert the angle
to degrees. In essence:

Angle in degrees = (180*arctan(y/x))/3.14

Also note that on your diagram, an angle of zero degrees is the boundary between
sectors 2 and 3. So:

an angle between 0 and 45 means sector 2
an angle between 45 and 90 means sector 1
an angle between 90 and 135 means sector 8

etc

Hope that helps!

Message is in Reply To:

View Thread Complicated Mathematics - Fr0stByt3 (223)
I have gone around and around with this problem for a while now. Let's say there is a circle divided into eight sectors, with sector one being from degrees zero to forty-five, [...]
(16 months ago, Jan 27, 2023, to Off Topic)

Message Has 1 Reply:

View Thread Re: Complicated Mathematics - chetzler (2342)
[...] An edit: The arctan function is only defined for angles between -90 (270) and 90. I glossed over that. So, as per your subject line, it is complicated! If x [...]
(16 months ago, Jan 27, 2023, to Off Topic)

10 Messages in this Thread:

 Msg 1 - Fr0stByt3 (223) 16 months ago Jan 27, 2023 to Off Topic
 Msg 2 - 0to60 (5817) 16 months ago Jan 27, 2023 to Off Topic
 Msg 3 - SylvainLS (46) 16 months ago Jan 27, 2023 to Off Topic
 Msg 4 - antant7 (645) 16 months ago Jan 27, 2023 to Off Topic
 Msg 5 - biglarge (44) 16 months ago Jan 27, 2023 to Off Topic
 Msg 6 - antant7 (645) 16 months ago Jan 27, 2023 to Off Topic
 Msg 7 « - chetzler (2342) 16 months ago Jan 27, 2023 to Off Topic
 Msg 8 - chetzler (2342) 16 months ago Jan 27, 2023 to Off Topic
 Msg 9 - ghyde (203) 16 months ago Jan 28, 2023 to Off Topic
 Msg 10 - molten.brick (13) 16 months ago Jan 30, 2023 to Off Topic

 Previous Message   Next Message 

Entire thread on one page
This message and all its replies on one page