Whats wrong with my forumla? (Trig)

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Jul 2008
Posts: 12
Reputation: scarypajamas is an unknown quantity at this point 
Solved Threads: 0
scarypajamas scarypajamas is offline Offline
Newbie Poster

Whats wrong with my forumla? (Trig)

 
0
  #1
Aug 3rd, 2009
Say I have a point A at (1,3) and a point B at (2,1) and point B has an angle of 45 degrees. I need a formula that will tell me which direction (right or left) B should turn so it points at A the fastest.

--(my attempt)--
I originally pretended that B was the center of a circle and A was on the ring of the circle. I then found the area of the sector and stored my results in SECTOR_AREA.

Next, I took the full area of the circle and divided it by 2 and called it HALF_AREA.

If SECTOR_AREA > HALF_AREA then TURN RIGHT
If SECTOR_AREA < HALF_AREA then TURN LEFT

The problem is I'm getting strange results with this ^^^ formula ^^^ and it's not working. I'm not sure why? Should it work? Might I have entered the wrong formula? What would be a good alternative to this?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 793
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Whats wrong with my forumla? (Trig)

 
0
  #2
Aug 4th, 2009
Read up on arctan. It might give you a few ideas...
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Whats wrong with my forumla? (Trig)

 
0
  #3
Aug 4th, 2009
There are several algorithms. Here are a couple...

N degree angle passing though point B is a line from + infinity to - infinity. Which side of the line is point A?

Inverse Tan y/x gives you the angle. of B-A
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 83
Reputation: nmaillet is an unknown quantity at this point 
Solved Threads: 18
nmaillet nmaillet is offline Offline
Junior Poster in Training

Re: Whats wrong with my forumla? (Trig)

 
0
  #4
Aug 4th, 2009
I am too tired right now to try that formula out. But you could consider:
if(A.angle < 180)
if(B.angle > A.angle && B.angle < A.angle + 180)
//turn counter-clockwise
else
//turn clockwise
else
if(B.angle < A.angle && B.angle < A.angle - 180)
//turn clockwise
else
//turn counter-clockwise
Again, really tired so those might be backwards. Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Whats wrong with my forumla? (Trig)

 
0
  #5
Aug 4th, 2009
Use fmod to handle angles set > < 360 degrees.

If you decide to use trig functions don't forget to convert degrees to radians.

PI is 180 degrees.
+/- PI.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 12
Reputation: scarypajamas is an unknown quantity at this point 
Solved Threads: 0
scarypajamas scarypajamas is offline Offline
Newbie Poster

Re: Whats wrong with my forumla? (Trig)

 
0
  #6
Aug 4th, 2009
Thanks for all your help guys, I was able to figure it out now
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC