4
\$\begingroup\$

I have a three dimensional pyramid given by four vectors a, b, c, d and want to test if a given vector x is inside that region or not. Here is an image:

pyramid and tested vector

A related question can be found here: 2D problem.

How can I test to see if the vector is contained by the others?

\$\endgroup\$
3
  • \$\begingroup\$ how can any one edit my question. \$\endgroup\$
    – Bilal Ayub
    Jun 23, 2014 at 15:16
  • \$\begingroup\$ i am still not understood by the answer \$\endgroup\$
    – Bilal Ayub
    Jun 23, 2014 at 15:16
  • \$\begingroup\$ Anyone can edit questions and answers. It's part of how this site works. If you don't understand a question or answer, or if you'd like to discuss an edit, leave a comment with the add comment-button under it and ask for clarification. \$\endgroup\$
    – Anko
    Jun 23, 2014 at 22:06

2 Answers 2

6
\$\begingroup\$

Think of your frustum as a set of planes defined by three vectors each. In your case, 5 planes (left, right, top, bottom, far). A typical frustum has 6 (near, far, left, right, top, bottom)

Take the dot product of each plane's normal with the point's location to get the distance of that point from that plane. If the distance is greater than zero, it's in front of the plane. If it's less, it's in back.

If all the plane's normals are oriented toward the centre of the frustum, then the point should be in front of all of them. That would indicate the point is inside. Otherwise it's outside the frustum.

If the normals are pointed out, then it would be in back. So if it isn't in back of all the planes, then it would be outside the frustum.

The normals of the planes will be determined by the winding order of your frustum's vertices. ABC -> normal "out," CBA -> normal "in." Just be sure that you always use the same winding order for plane vertices and everything will be okay.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The idea here is nice, to cut the space with the five planes into the region of interest. Calculating the five normals and five dot products is conceptually easier than calculating a matrix inverse with Zassenhaus algorithm or similar. \$\endgroup\$
    – mvw
    Jun 23, 2014 at 21:47
3
\$\begingroup\$

First bit is to get a model of the pyramid's bottom rectangle R. Define

u = b - a = (b1 - a1, b2 - a2, b3 - a3)

v = c - a = (c1 - a1, c2 - a2, c3 - a3)

If the bottom is really flat then the equation

d = u + v

should hold (otherwise vector d is ignored).

The rectangle R is defined by

R = { y | y = a + α u + β v ∧ 0 ≤ α ≤ 1 ∧ 0 ≤ β ≤ 1 }

To test for the whole pyramid, one can scale R along a, meaning moving the rectangle along the vector a, giving a scaled rectangle R'.

u' = f (b - a)

v' = f (c - a)

x' = x - f a

with 0 ≤ f ≤ 1. This leads to the equation

(x - f a) = f α u + f β v

-a = α u + β v + t (-x)

y = A^-1 b

with A = (u; v; -x), b = -a and y = (α, β, 1/f).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .