Single axis object space move to parent objects ground plane - MAYA

Can anyone help me with a script that moves a child object along its local y axis to the parent objects ty of zero in the parent local space.
So not just grabbing the ty value and moving it up.
Note both the parent and child have differening rotational values

The same thing you would accomplish from grabbing its local axis in the viewport and sliding it along y until it aligns with the parents. So the channel box values of the child would all have to change.
I assume it needs worldMatrix calculations to achieve this.
Here is the result achieved in the viewport

goal

to elaborate this is a kind of smart “snap to ground” function that I will embed in a larger context of “do this on everyframe the locator is below the parents tY0”

You’re asking “Where along the line of the Y axis of my object does it intersect the XY plane of its parent?”. The google term is “Line Plane Intersection”

There’s a couple main ideas to make this possible:

  1. If you make a line that’s perpendicular to the plane, then any other line that’s perpendicular to that line MUST be exactly on the plane.

  2. The dot product of 2 vectors is 0 if and only if they’re perpendicular

  3. If you have a point and a direction vector, that point plus some random multiple of the direction gives you a new point on a line.

Using those 3 ideas together: If we move some multiple of a direction from our starting point, and dot that with the normal, and it equals 0, then we’re on the plane.

Using that we can make an equation, which we can directly solve for that “some multiple”, which you can add to the Y translation to get to the plane.


I don’t have time today to give you a FULL writeup … so I just googled it and found a Stack Overflow answer that seems worth trying :smiley: 3D Line-Plane Intersection - Stack Overflow

And just a little optimization you can do: the vector u in the SO answer is equal to the second row of the matrix of your object divided by the Y scale value.

1 Like

Hi tfox_TD

Thank you for explaining the maths logic, and also knowing exactly what to call this term.

I have to admit this is more complicated than I first thought, and a little beyond my current coding skills (I am migrating from mel scripting to python slowly, but very keen to grow this skill)
If you have time I’d love to understand more how this can be written into a script to apply on a given selected locator and a plane.

my python wiz friend at work seems to think this can all be done with maya matrix maths (but I couldnt get his method to work)

You can quickly get a prototype using a variety of methods to approach a given problem. For example:

  1. A simple way to find the intersection of a ray with a plane (using elementary vector mathematics).
  2. Using the Maya API and the closestIntersection function
    Both methods are discussed in detail here:
    Intersection of a curve and a mesh - #8 by VVVSLAVA
    Even if you don’t use the closestIntersection function, it still makes sense to use the Maya API. Because then you get high-performance tools for working with vectors and Maya matrices out of the box.
    Using transformation matrices will certainly help you better understand the “kitchen” of any 3D application. But in the context of your problem, this is just an additional method.
    To quickly get and set transformation matrices, you can use the command xform with key -matrix with subkeys -worldSpace,-absolute, etc:
    xform command
    Also, if you were to describe the global goals that your code should fulfill, then perhaps a more efficient solution could be found using other methods.
1 Like

This is a great resource for understanding the plane equation and ray plan intersection works:
https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection.html

If it looks a bit daunting don’t worry, write down notes for what each notation stands for and look at it like a simple equation :+1:

1 Like