Which direction does PositionA lie relative to root PositionB (Topleft/top/topright/etc) taking into consideration rotations

Hey guys. I have an enum of ‘Locations’, here:

public enum Location
{
	TopRight,
	TopLeft,
	BottomLeft,
	BottomRight,
	Central,
	CenterLeft,
	CenterRight,
	CenterTop,
	CenterBottom
}

Now I have a transform with a positionA, and it is rooted to positionB (Also, the game doesn’t worry about the Y axis, only X/Z. 2D game). I am trying to figure out which ‘location’ the position will fall in to. I can work this out very simply by doing a with X/Y checks to see where the point lies, but this does not take into consideration the rotation of the parent and because I am using world positions, my results get all whack.

The reason I can’t stick to only using local locations is because the solution should be able to work on the positions of the childrens children, etc. So that is, Point X could be a a child of point Y, which is (finally) a child of point Z, but the ‘location’ of Point X should be relative to the root objects position, point Z.

An illustration:

alt text

	TopRight, green
	TopLeft,red
	BottomLeft,purple
	BottomRight, blue
	Central, white
	CenterLeft, black
	CenterRight, pink 
	CenterTop,yellow
	CenterBottom, grey

Currently, what I am doing is using the angle between (positionA’s worldpos - positionB’s worldpos) and (positionB’s forward vector). This returns an angle between 0 > 180 (I work out the angles polarity by doing a cross product between positionA’s world pos and positionB’s forward vector). I then use this angle to determine which Location i should slot the object in to. But then I get a distributions that is more like this, and not what I am after:

alt text

I found my solution with “InverseTransformPoint” function. I basically use this function to convert the position of PointA to local space of the root object. Then i conduct simple if pointA.x > 0 etc tests to determine where it lies.

Vector3 otherLoc = transform.InverseTransformPoint(_section.gameObject.transform.position);

if(MoreMaths.RoughlyEqual(otherLoc.x,0,0.25f))
{
	if(MoreMaths.RoughlyEqual(otherLoc.z,0,0.25f))
		return SectionLocation.Central;
	else if(otherLoc.z > 0)
		return SectionLocation.CenterTop;
	else if(otherLoc.z < 0)
		return SectionLocation.CenterBottom;
}
else if(MoreMaths.RoughlyEqual(otherLoc.z,0,0.25f))
{
	if(otherLoc.x > 0)
		return SectionLocation.CenterRight;
	else if(otherLoc.x < 0)
		return SectionLocation.CenterLeft;
}
else if(otherLoc.z > 0)
{
	if(otherLoc.x < 0)
		return SectionLocation.TopLeft;
	else
		return SectionLocation.TopRight;
}
else 
{
	if(otherLoc.x < 0)
		return SectionLocation.BottomLeft;
	else
		return SectionLocation.BottomRight;
}

return SectionLocation.Detached;