Jun 22 2012

Crank your engines!!

20120621-145508.jpg
Engine pistons/Cylinders are a complex task for any rigger..
They seem surprisingly easy at first but can take a about every trick on the book to get this things to work with out having the shafts wiggle at the pivots. Anyway I had some downtime at work so I set my self to find a logical mathematical approach to address this setup with a single expression 🙂
The trick here.. Is knowing how much to offset the Cylinder inside along it’s path of least resistance, so that when we apply an aim constraint to the shaft the distance between pivots is always constant..
Here’s an initial image illustrating my method to solving for this position, let my warn you that, I have almost zero proper math education so this image is probably no where near the universe of proper math notation 🙂

20120621-150302.jpg

So the basic idea for me was that “P” is a locator that describes the center of the Cylinder with one of it’s axis describing the direction in which it slides (“L”). “P1” is a locator that will serve as the position in which the the shaft will pivot in relationship to the crank, while “Dis” is the length of the Crank it self.  now the key to solving this problem, was to build upon the previously discussed ClosetPointOnRay algorythem we discussed early in this thread, which render “P2” the closet point to P1 along Ray “P”,”L”..

if you look closely the relationship between  points p, p1, p2 is that of a right triangle. which means we can apply the “pythagoras theorem” to solve for “Dif” the distance between “P3” (the final solution to our problem) and “P2” once we have “Dif” then we can easily derive p3 by simple offsetting p2 along L by a distance of Dif..

here’s a snippet of the maxscript code i put together to test this..

dis = 62
p = $'Point'.transform.position
L = normalize $'Point002'.transform[2]
p1 = $'Point001'.position
p2 = closestPointOnRay (ray p L) p1
N = distance p1 p2
dif = sqrt((dis*dis)-(N*N))
p3 = p2 + (normalize(p - p2) * dif)
-- $'pOR'.position = p2 --this was added to visualize the closetPointOnRay
format "n=% dif=% p3D=%\n " N dif (distance p3 p1) --format to help debugging
p3

anyway here’s a quick video of the final result…
httpv://youtu.be/Urh9kYd0ywM

Leave a Reply