Advertisement

How can I detecting if a line segment has too much directional or rotation variance?

Started by September 06, 2020 02:55 PM
3 comments, last by judeclarke 4 years, 5 months ago

I am trying to understand how to detect if a line segment based upon a direction would be within a +/- rotation. I can't seem to understand how though. What I appear to be lacking is the jumping off point to figure it out.

What I have are two objects, A (the blue square) and B (the purple square). Using the direction and position of object B I would like to know if the line segment to A is within a certain rotation range. An example of this being correct is Figure A but an example of it being incorrect is Figure B because the line segment crossing over the range (presented by the green line for in range and red line for the range being crossed over)

Relative to B, what is the accepted angle range?

(you should be able to derive the angle from the points at the other end.)

Relative to B, what angle is A at?

Advertisement

To avoid expensive trig, you can work with dot product instead angle

vec3 dirB = objectB.CalcLookFordardDirection(); // returns unit vector
vec3 diff = objectA.position - objectB.position; // get the black line from your image
diff.Normalize(); // make unit vector too
float dot = dirB.Dot(diff); // if they are equal we get 1, if they are orthogonal we get 0, if they are opposite directions we get -1
// float angle = acos(dot); // we might not need this
if (dot > 0.9f) // this constant defines the angle between the green lines of your image
{
	// B can see A
}
else
{
	// B can not see A
}

@JoeJ Thank you, this is exactly what helped me

This topic is closed to new replies.

Advertisement