| | |
Whats wrong with my forumla? (Trig)
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Jul 2008
Posts: 12
Reputation:
Solved Threads: 0
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?
--(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?
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
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.
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.
![]() |
Similar Threads
- Can anyone please find whats wrong in this code (C++)
- Anyone know whats wrong with this union? (C)
- whats wrong in this code? (PHP)
- whats wrong with the code......... (PHP)
- Please help me i dont understand whats wrong with my code (C++)
- Whats wrong with my computer??? (Viruses, Spyware and other Nasties)
- Whats wrong with this class??? (C++)
- merged:nesting loops (C++)
Other Threads in the Computer Science Forum
- Previous Thread: Program language for Health related software
- Next Thread: Please help me design a operating system
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignmenthelp assignments battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business cern codebreaker compiler computer computers computerscience computertrackingsoftware connect conversion csc dataanalysis dataintepretation development dfa dissertation dissertations dissertationthesis dissertationtopic ebook employment energy floatingpoint foreclosure foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet ipod itcontracts jobs kindle laser laws linkbait lsmeans mainframes marketing mobileapplication msaccess nano netbeans networking news os p2p piracy piratebay principles programming rasterizer research sam-being-cute sas science security sex simulation software spying stephenfry study supercomputer supercomputing sweden technology textfield turingtest two'scompliment uk virus ww2





