Friday, 20 May 2016

Line Plane Intersection

I went with line plane intersection this time around, for a couple of reasons.
First off, there's some excellent info on it already, This one really solidified it for me because it broke the process down step by step.

Having said that, these sorts of topics can be difficult to look at on paper sometimes..I mean, how does one go about visualizing the equation for a plane?

Anyway, on to it. I built this node in C++ using one of the examples in the devkit as a template. Surprisingly, there isn't too much manual work if it's a relatively simple compute and starting from a template makes things much easier. I think I spent the majority of the time learning the syntax for different input attributes.

As there is already so much good info out there for this topic, I'll just go over the first couple of steps of how I got the normal of the plane, without using any of the convenience methods in MFnMesh, MItGeometry etc.


First off, we're looking for pX. The point of intersection with the plane if we were to extend the vector from p0 to p1. Think of it kinda like shining a torch onto the floor, and you're aiming the torch 5 metres in front of you. You can roughly gauge where the light will hit, but where exactly is it going to hit? Using this example, p0 is the butt* of the torch and p1 is the light cone or front of the torch.

To start off with, we need to get the normal of the plane, a vector perpendicular to the plane. It's labelled n in the picture above.

Imagine the plane as a polygon that covers a floor, and the points A, B & C as the corner points. The floor might have a fourth point (corner) or more, but we only need three points to define a plane.

Get the vector from A to B.

AB = B - A

Now get the vector from A to C.

AC = C - A

Take the cross product of AB and AC. This will give you a vector perpendicular to both AB and AC.
It matters which way round you do this as there are actually two vectors perpendicular to the plane (think towards the ceiling and down through the floor..).

AD = AC x AB

Now we have our vector AD, it's just a case of turning it into a unit vector, represented as n in the first image.

Check out the tutorials I've linked to at the start to go from here.

Here's a quick demo of the C++ node in action.

Use case example: Finding a position for a pole vector

I re-built it in Python to take in the three points we need to define a plane. If I connect up the three joints of an arm or leg we can find a position for a pole vector that won't offset the joints when applied.
I'll admit, it's probably not the best way to go about building a pole vector but still, I think it's good insight to how the pole vector stuff works.

Plugin (Python)

* heh

No comments:

Post a Comment