Orient 3 points on mesh to a plane

Hi, I’m working on a new problem and wanted to start a thread to help guide me in the proper direction. The community here has always been helpful and I will follow up with a PG for documentation and support.

I intend on orienting a mesh to a plane by 3 points. The user picks 3 points and the mesh moves such that those 3 points are on a plane (pre-defined ground plane). The points will also describe the orientation / alignment with global axes (pt 1 at origin and pt 2 along x axis and pt 3 as positive y). It could be interactive in that after each pick the point moves to the plane and keeps the previous point on the plane, or move all at once after the points are defined.

What’s a good strategy here? Below is what I’m going to work on:

1. move point 1 on mesh to origin
2. set mesh pivot as origin
3. get point 2 location
4. get difference of plane and point2
5. move (with origin as pivot) the difference
6. create new pivot based halfway between origin and pt2 (maybe make a line and use midpoint)
7. get point 3 and move difference to plane from the new pivot.

Not 100% sure my process will get me there but I’m going to start on it later this week. I’m also interested in some of the built in matrix translation tools that may make the math easier. I always appreciate the communities feedback!

Thanks!

It is not possible to fulfil all of your conditions. If all three points p1, p2, p3 lie on the ground plane then p3 cannot be positive y as in Babylon.js Y is vertical.

Even if you are thinking of Y as a horizontal axis and p1 and p2 along the X axis then for p3 to be on the Y axis it cannot be an arbitary point on the mesh.

Here is a rough and ready PG to give you some ideas Babylon.js Playground

Now positions plane on ground https://playground.babylonjs.com/#SIW3I4#1

2 Likes

John, your response and PG are tremendously helpful. Thank you for this. Your code is much cleaner and straightforward than my initial non-working one.

I should be able to add a slider / rotation feature to get the points oriented once on the plane.

Your rotationQuaternion, Axis.subtract, and Vector3.Cross are also the built in methods I was looking for.

I’m going to study this a bit more and keep playing. Huge jump start. Thank you!

2 Likes