View Full Version : scirpted controller - shortest distance to splineShape (knots)

 jonahhawk11-18-2010, 06:47 AMFor some reason search is down... if this has been covered, I apologize. Inspired by the hexagon screen forms here. (http://www.notcot.com/archives/2010/11/mercedes-benz-sculpture-experi.php) And by the work of Ali Torabi (http://www.torabiarchitect.com/blog/?page_id=190) I wrote a scripted controller that finds the shortest distance to a splineShape. In my crude method, I added a Normalize Spl. Mod to the shape then collapsed it to work with the splineShape. The script makes an array of all the distances, sorts the array then uses the first value. I'm sure there is a better/faster way of doing this. And maybe a way to not use the Normalize Spline mod. Is there a way to get an array of points evenly spaced along a spline without Normalize Spl. mod? Is there a faster way to find the shortest distance? This controller goes into hundreds of objects to control properties in proximity to the shape. theMin, theMax, theFactor are contstants. nPos is the position track of the object, an ngon in this case. theDistances = #() for s = 1 to (numSplines theShape) do ( for k = 1 to (numKnots theShape s) do ( knt = getKnotPoint theShape s k theDist = (distance nPos knt) append theDistances theDist ) ) sort theDistances ( if theDistances[1] < theFactor then ( if (theDistances[1]/theFactor) < theMin then theMin else (theDistances[1]/theFactor) ) else theMax )
jonahhawk
11-18-2010, 07:20 AM
theDistances = #()

for s = 1 to (numSplines theShape) do
(
for k = 1 to 100 do
(
p = (lengthInterp theShape s (k*.01) )
theDist = distance nPos p
append theDistances theDist
)
)
sort theDistances

(
if theDistances[1] < theFactor then
(
if (theDistances[1]/theFactor) < theMin then theMin else (theDistances[1]/theFactor)
)
else theMax
)

rafoarc
11-18-2010, 11:59 AM
I guess if you need an efficient closest point algorithm you would need to find the two closest points using the lengthInterp, somehow make sure that they are actually next to each other and then interpolate again along the curve between those two points. Doing this iteratively will get you pretty close to the actual closest point.
I've been working on distance based controllers quit a lot lately... using points however, not curves... something like this (http://object-e.blogspot.com/2010/07/glowing-cloud-parametric-model.html)...

denisT
11-18-2010, 12:28 PM
does measureOffset or nearestPathParam not work for you for any reason?

jonahhawk
11-19-2010, 04:53 AM
Only because they were not in my brain. Now that they are there, they work great!

Thank you Denis

jonahhawk
11-20-2010, 02:00 AM
Nice work there Dimitris. I like the positive/negative attractors. Are you controlling the Inner Amount and Outer Amount of a Shell mod?

denisT
11-20-2010, 02:30 AM
Only because they were not in my brain. Now that they are there, they work great...

they works... but it's so boring. it's cool to find closest knots, to do the linear approximation, to calculate the integral... isn't it? oh, how i wish to have a time for doing it...

rafoarc
11-20-2010, 01:21 PM
Nice work there Dimitris. I like the positive/negative attractors. Are you controlling the Inner Amount and Outer Amount of a Shell mod?
Thanks. Yes, it is the inner and outer amount of a shell mod in the first case, and the bevel and inset amount of a poly in the second.

As, to the build in functions, they are great, but maxscript has so many of them that it is hard to know that they exist... so several times you end up writing functions that already exist...

CGTalk Moderation
11-20-2010, 01:21 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1