point & Octahedron relationship

Started by
5 comments, last by quasar3d 9 years, 6 months ago

hello

i have a point M, & i have an octahedron (shape with 8 faces), how can i detect that the point M is outside or inside that shape?

is there any rule or mathematical method to get that?

Advertisement

There's likely a more efficient method. However, if you know the points that make up the faces (triangles),

1. calculate the normal for each of faces (triangles).

2. For each of the faces, calculate the dot product of the vector (point-in-triangle - M) and the normal for that triangle. "point-in-triangle" is any of the three vertices making up that triangle.

If all the dot products are > 0, point M is inside the octahedron.

EDIT: If you know that it's a regular octahedron, you can save a couple dot product calcs. You can calculate the normal for one of the three planes that bisect it. Calculate the dot product of (point-in-plane - M) and the normal to the plane. If the dot is positive or 0, use steps 1 and 2 above for just the faces on the "positive" side of that plane. If the dot is negative, use steps 1 and 2 above for just the faces on the negative side of that plane.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

& what about 2D shape (i mean a shape with 8 lines)?

In 2d, shoot a ray out in any direction. If it crosses the lines of the shape an even number of times (0 is even here), you are outside. If it crosses odd number of times you are inside.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

In 2d, shoot a ray out in any direction. If it crosses the lines of the shape an even number of times (0 is even here), you are outside. If it crosses odd number of times you are inside.

Note this also works in 3D if the polygon is closed. It's a pretty elegant (if intuitively obvious) theorem.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


Note this also works in 3D if the polygon is closed. It's a pretty elegant (if intuitively obvious) theorem.

Good observation (if you change the word "polygon" to "surface"). And that would include irregular surfaces. Note to the OP: that method requires boundary checks for each intersection ("Is the intersection point at or within the bounds/endpoints of the face/line?") And, if the intersection point is through a vertex, that intersection must count as a "hit" on each face/line that shares that vertex.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

If it's a regular octahedron, just take the absolute value of each coordinate, add them, and see if the resulting value is less than a certain threshold (ie. the size of your octahedron). If so, then your point lies inside it, otherwise not.

This topic is closed to new replies.

Advertisement