#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Circle Degree Algorythm

Posts: 14Member
If I have x & y coordinates to 2 points,
point 1 would serve to be the center of an imaginary circle.
point 2 could be any point in relation to point 1.
I want to know the degree of an angle that would be created with the 2 points (assuming the 1st line of the angle is straight up from point 1, the 2nd line is the line connecting point 1 with point 2)

Example.
Point 1 = 50,100
Point 2 = 52,100 or 354,100
Degree would be 90 (a perfect right angle)

I'm sure there's a mathematical formula for this but I don't know it... can anyone help?

· ·

• Posts: 272Member
Try using cos and sin functions,
most languages have them

· ·
• Posts: 13Member
the formula is
360*(1 - cos'(h/w)/pi)
where
cos'() is inverse cos()
h = |y2-y1|
w = |x2-x1|
pi = 3.1415

if you're after speed or your software does not support trig functions you can easily formulate a polynomial to approximate for quandrant 1 using series and mirror|translate for all other angles.
· ·
• Posts: 21Member
: the formula is
: 360*(1 - cos'(h/w)/pi)
: where
: cos'() is inverse cos()
: h = |y2-y1|
: w = |x2-x1|
: pi = 3.1415
:
: if you're after speed or your software does not support trig functions you can easily formulate a polynomial to approximate for quandrant 1 using series and mirror|translate for all other angles.
:

If you aren't satified with this or you can't use the trig functions for some reason I will supply you with them (the real onece)in a few days when I get home (I'm at my sisters place.. no notes filling my desk). They are not easy to understand mind you and they certainly are not easy to use either.
· ·
• Posts: 1Member
I need a generic algorithm for computing the average (mean) of two degree parameters. If I pass 359.0 and 1.0, I need it to return 0.0. The two parameters can be any degree values between 0 and 360. Any suggestions anyone? Thanks.
David

· ·
• Posts: 21Member
: I need a generic algorithm for computing the average (mean) of two degree parameters. If I pass 359.0 and 1.0, I need it to return 0.0. The two parameters can be any degree values between 0 and 360. Any suggestions anyone? Thanks.
: David
:
:

let me see if I got this right:
you got degree a and degree b and you need to find (a+b)/2?
it's quite simple if that's what you need. If not I'm not understanding this correctly
· ·
• Posts: 3Member
: I need a generic algorithm for computing the average (mean) of two degree parameters. If I pass 359.0 and 1.0, I need it to return 0.0. The two parameters can be any degree values between 0 and 360. Any suggestions anyone? Thanks.
: David
:
:
Good question Dave, easy answer

((argument1 + argument2) % 360) / 2

the % is for modulus.
· ·
• Posts: 3Member
: : I need a generic algorithm for computing the average (mean) of two degree parameters. If I pass 359.0 and 1.0, I need it to return 0.0. The two parameters can be any degree values between 0 and 360. Any suggestions anyone? Thanks.
: : David
: :
: :
: Good question Dave, easy answer
:
: ((argument1 + argument2) % 360) / 2
:
: the % is for modulus.
:

sorry, that is not right answer, let me check some notes when i get home tonight, i solved this before.
· ·
• Posts: 3Member
: : : I need a generic algorithm for computing the average (mean) of two degree parameters. If I pass 359.0 and 1.0, I need it to return 0.0. The two parameters can be any degree values between 0 and 360. Any suggestions anyone? Thanks.
: : : David
: : :
: : :
: : Good question Dave, easy answer
: :
: : ((argument1 + argument2) % 360) / 2
: :
: : the % is for modulus.
: :
:
: sorry, that is not right answer, let me check some notes when i get home tonight, i solved this before.
:

~~~~~~~~~~~~~~

One way to solve problem is break into two parts.
Trouble comes when the numerical difference between arguments is greater than 180. Also, an exact difference of 180 can go either direction.

INPUT ARG1, ARG2
IF ABS(ARG1 - ARG2) <= 180
ANSWER = (ARG1 + ARG2) / 2
ELSE