Jump to content
  • Advertisement
Sign in to follow this  
abdellah

point & Octahedron relationship

This topic is 1337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Edited by Buckeye

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!