Operation with angles

I think that this is basically a math problem, But I don't know how to be applied on programming.

I have to calculate the distance, in angle degrees, between two points on a circle.
I read the position of my cursor and I have to calculate the distance from a specific point of the circle.
For example the cursor is located at 350 degrees (acquired from a sensor) my "limit variable" is 10 degrees. I know that the eagle between the cursor and the limit is 20 degrees... but how can I program Arduino to make the operation?

Thank you in advance.

M.

Your first step is to determine the radius of your circle. That will give you the length of two sides of a triangle.

The output is angle between points. What are your inputs ?

The angle of any point on a circle is the arc tangent of y/x (or something like that) :slight_smile:
Get the two angles and subtract them.

arc tangent function is in math.h

It is not at all clear what this means. Please try again, and maybe draw and post a diagram showing the circle and the points you mention.

I need to calculate the angle between Cursor position and Limit A. And The cursor position and Limit B.
Limit A and B are defined by user. Cursor position is acquired from a sensor that returns the position in degrees.

Do you know where the center of the circle is? How is the sensor measuring 350 degrees?

So what form of data are Limit A and Limit B expressed in?
If they are also degrees, then it is fairly straight forward A <=X<=B. Well, complicated by the fact that you have to recalculate zero to be at one of the limits, because normally degrees reset from 359 to 0 at the "north pole".
If they are locations, e.g. -40,-20 or 12,57 Then you want to convert them from rectangular to polar. Polar coordinates are a vector, that is, distance along a direction (degrees or radians).
After conversion you would then compare the degrees of all three.
I hate to duck the question, but if you need to convert rectangular to polar there are many resources available that are better than any explanation I could give.
You just have to know what you are searching for.

  • Wes

If the two are given as angles, subtract one from the other, modulo 360.

delta = (a - b + 360)%360;

But you still have not made clear how these positions are defined.

To find the shortest path,

if (delta>180) delta = 360 - delta;

are limit A and B in degrees or x,y coordinates? do you know the radius or need to compute it?

I think the OP is saying that angles A, B, and E are known, and they need to find angles C and D.

image

I've taken the liberty of showing A and B as measured CW from the red reference line, and E as CCW from the line. Also, C and D are shown as the smallest angles...

One thing missing is the question of "which side" do you consider "between" to be on?
The "cursor" position he drew is, by one argument, between A and B. However, there is a point 180 degrees opposite that is also "between" A and B. That is to say, there are two solutions as drawn, and we can guess that only one will be correct for his application.
I have no idea how the "cursor" is input, but if it can be arbitrarily placed without some other restrictions, such as a starting point that is assured to be "between", a single solution is impossible.

  • Wes

What is the function of "Limit A" and "Limit B", and why would the user want to define them?

Exactly. I have to find C and D.
Limit A and Limit B are fixed. once set they don't change.

you're not going to get a direct answer without answering the questions put to you?

The example on the first post is clear: limit A: 10 degrees cursor position: 350 degrees.
Everything is defined in degrees. If a radius is needed to calculate the angle can be considered as 1

`degDist = degA - degCursor = -340`
if (degDist < 0)
    degDist += 360 = 20

yes...
now that I see the code I'm realizing that was so simple...

thank you!

I asked what your inputs where at the top of the post. Knowing it was angles would of saved a lot of time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.