# Circle Degree Algorythm

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?

• Try using cos and sin functions,
most languages have them

• 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.
• : 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.
• 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

• : 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
• : 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
:
:

((argument1 + argument2) % 360) / 2

the % is for modulus.
• : : 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.
• : : : 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
ENDIF

The else clause is harder to work out. But the IFTHENELSE construct will at least identify the 'situation' where special processing is needed.

Hope that helps.

I haven't taken any trigonometry, but i'll bet there is a formula which can work in all situtations.

#### Howdy, Stranger!

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