Copy link to clipboard
Copied
Comparing one object to another, and I'm wondering if there is a more efficient way to determine what quarter an object is in relation to another one.
Currently I am doing
if (object1.x > object2.x){
if(object1.y > object2.y){
//quarter 1
} else {
//quarter 0
}
} else {
if(object1.y > object2.y){
//quarter 2
} else {
//quarter 3
}
}
Thanks in advance.
Search Google using the terms "AS3 ATAN2 follow object" You are likely to find a lot of stuff that talks about following the mouse... just replace the mouse with the object you want to point to.
Copy link to clipboard
Copied
I don't think it works as you wish it would. Place object 2 in quadrant 0 and object 1 in quadrant 1 - you don't have a case where 1x is not greater than 2x where the answer is q2 or q3. I believe the same holds true if you switch them.
PS - it's late (for me), so if I miss seeing something that makes your solution right I accept my error.
Copy link to clipboard
Copied
Sorry if that was unclear, object1 is the center and I want to know which quad object2 is in.
Copy link to clipboard
Copied
It wasn't a matter of being unclear, more a matter of not being explained. What you have is as simple as you need it to be. There are probably other ways you could write the code or determine the relative positioning, such as using angles, but in the end you still need to make comparisons and include 4 possibile solutions.
Copy link to clipboard
Copied
That's actually why I am wanting to know what quad one object is in relation to another, to rotate a line to the correct angle between 2 objects.
Could you expand a little on what you meant by using an angel to do it?
Copy link to clipboard
Copied
Search Google using the terms "AS3 ATAN2 follow object" You are likely to find a lot of stuff that talks about following the mouse... just replace the mouse with the object you want to point to.
Copy link to clipboard
Copied
Atan2 Rotation in Actionscript | lashf.com
Simple and easy, thanks for the help that's actually a lot simpler then me trying to break trigonometry by creating a way to calculate the angle of a triangle without sin/cos/tan.
Copy link to clipboard
Copied
You're welcome Bryan