• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Most efficient way to figure what quarter an object is in relation to another

Guest
May 28, 2015 May 28, 2015

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.

quarter.png

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.

TOPICS
ActionScript

Views

381

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 29, 2015 May 29, 2015

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.

Votes

Translate

Translate
LEGEND ,
May 28, 2015 May 28, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 28, 2015 May 28, 2015

Copy link to clipboard

Copied

Sorry if that was unclear, object1 is the center and I want to know which quad object2 is in.

quarter.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2015 May 29, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 29, 2015 May 29, 2015

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2015 May 29, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 29, 2015 May 29, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2015 May 29, 2015

Copy link to clipboard

Copied

LATEST

You're welcome Bryan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines