# point & Octahedron relationship

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

## 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 on other sites

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 on other sites

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

##### 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 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 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 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.

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633657
• Total Posts
3013200
×