reverse Splines

Hi there,
I'm trying to develop some spline oriented scripts such as a non-destructive cleaner/optimizer for imported CAD splines and some architecture tools later...

I tried to look up for spline functions but am surprised how few access there is to common max spline operations. As far as I know there is no function telling if a spline is built clockwise or the other way round, just one to 'reverse' it...
Would really be helpful if I want to develop a scripted version of spline 'outline' which also is not accessible through MaxScript (correct me if I'm wrong)...

So if anyone got input on this or an algorithm for checking a closed splines direction - I'd be delighted.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Garp's picture

Doesn't look like it.

It's more like max always draw the positive outline starting from the left of the spline as seen from vert1 to vert2 and when looking at the spline from the positive Z side.
Otherwise it couldn't outline a straight line, could it?

Garp's picture

How long is a rope?

jimflim, your question doesn't make sense.
CW or CCW from which point of view? And even so, the verts can be anywhere in space. How about self-intersecting shapes, like an '8'? No matter how you look at it, part is CW and part CCW.

Now if you know that all the splines are lying flat in the xy plane AND they're seen from above AND they're not self-intersecting, you can write a script for this very particular case (one among an infinite number of other possibilities).
Look at the cross product. Take three consecutive verts - like 1,2 and 3 - and use cross (p3 - p2) (p1 - p2). Then look at the z component of the result. If it's positive, the spline is CCW. If it's negative, the spline is CW. If it's zero, try again with verts 2, 3 and 4.

jimflim's picture

Of course the verts can be

Of course the verts can be anywhere in space but Max still stores a CW or CCW direction in each shape somewhere which makes the 'outline' function possible and tells max to outline to the outside and not to the inside of the spline, even if the points are located in 3D space.

Anubis's picture

there is reverse function

from the mxs-help:
reverse <shape> <spline_index_integer>
--reverses the order of the knots in the indexed spline.

and to get direction measure 2 knot coords, for exmple 1st and 2nd.

my recent MAXScripts RSS (archive here)

jimflim's picture

yes I wrote about that

yes I wrote about that function, but I need to know the state in which the spline lies. reversed or not.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.