Jump to content
  • Advertisement
Sign in to follow this  
Baf

compute point coord in a mesh

This topic is 4837 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

Does someone know a way to compute if the coordinates of an arbitrary point (not a vertex)is in a mesh?

Share this post


Link to post
Share on other sites
Advertisement
Well two methods pop into my head. The best one is to cast a line through that point. I don't say ray, because the starting point is irrelevant. For all practical purposes, you should be able to cast a line with any function, as long as that point lies on the line. I would recommend using an axis alligned line though, so that the equations can be simplified. Next, determine all intersection points on that line with the mesh, keeping track of whether the line is entering or exiting the mesh at each point. It won't intersect directly with vertices in most cases probably, so you will have to interpolate between vertices (and hopefully you aren't using higher order meshes). The last part of the algorithm involves determining where the point lies. It should be between an entry point and an exit point. If you want to simplify a lot of the math, I'm sure you could just cast a ray using the ray picking example in the SDK, just making sure that the ray goes through that point.

The other method is slow and I don't really see any benefits other than perhaps a bit easier to compute. You would just go through all faces in the mesh and determine if they all enclose the point. i.e. if the mesh data contains face normals, you can determine which direction the face is "facing" and if the point lies behind that face in the x,y,z values, it is at the least behind that one face. Then you could check all faces similarly. If all pass, it's within the mesh. If one fails, it is not. Think of a face as a plane. There are D3DX functions that will determine if a point lies in front of, within, or behind a plane.

Drawbacks:
The first method will have issues when the line lies parallel and on top of the mesh (i.e. the mesh wall runs through the line long ways). There would obviously be numerous intersection points...

The second method may be very slow for large meshes.

Sorry if I've left anything out or said something wrong, just kind of threw this together to get the thought process going for you.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!