Point to Plane question

Recommended Posts

My question has to do with how to generate a vector from a point to the nearest point on a plane.  If I have a mesh moving inside a box, I want to know the distance and direction from the mesh position to each side of the box.  I understand that would be a vector perpendicular to the plane that intersects the point.

Does Babylon have a method that will do that for me?  TIA

Share this post

Link to post
Share on other sites

Hiya K! 

Um... I have some quick thoughts.  Imagine that your box is made from 6 planes, positioned to form a box shape.  Then...

distance = BABYLON.Vector3.distance(mesh.position, oneWallOfTheBox.position);

and direction... umm... you get that by... umm...

direction = mesh.position.subtract(oneWallOfTheBox.position)   // I think.  Or maybe it's...

direction = oneWallOfTheBox.position.subtract(mesh.position)  // not sure.

How to determine which is the nearest wall of all 6?  I dunno.  Perhaps, whenever mesh is moved, you need to check .distance() on all 6 box walls.  The lowest distance as the nearest wall.  ??  hmm.

I think there may be fancier and/or easier ways to attain these values.  Let's listen for more/better replies.  Using a "ray" (similar to a picking ray)... might give you direction and distance all in one little piece of code, but I am not a ray master.


There is some "ray" activities happening in the line 62 area.  Not sure about the story, there.  It looks as-if SOMEBODY almost knew what they were doing, though.  :)

That PG was found via a playground search for 'distance'.

Share this post

Link to post
Share on other sites

Planes have normals, which are perpendicular, so you can work from there backwards (computeWorldMatrix updates everything, if you move the planes around).
The normal, if you are inside a box will probably be facing outwards, so you may not need to .negate() the Vector3 as I did.

If you don't want to write any math, you can use rays like in the PG.  Otherwise the normal of a plane can be calculated as the Cross from subtracting the corners (see comment in PG).


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.