POV-Ray : Newsgroups : povray.advanced-users : Adding forces to points in curves : Re: Adding forces to points in curves Server Time
30 Jul 2024 06:19:38 EDT (-0400)
  Re: Adding forces to points in curves  
From: Mike Williams
Date: 28 Dec 1999 02:46:16
Message: <Y74hBDACkAa4EwJE@econym.demon.co.uk>
Wasn't it Rune who wrote:
>Thanks to the repliers to my previous message.
>I haven't found a solution yet though.
>I'll try to explain my problem in greater detail:
>
>I'm trying to make a long neck-like thing. I must be able
>to set the point where the neck starts and ends. Also the
>normal of the neck in these two points. ("normal" is
>probably not the right word. "Vector" or "direction" is
>probably better, but I'll just use "normal" here) I also
>want to control the length of the neck and the number of
>"links" or segments it is made of. ( The length of each
>"link" would then be [length-of-neck] / [number-of-links] )
>
>I can't just use a simple spline. To use it at all I would
>first have to calculate it's length, then change the length
>of the normals, that way also the length of the spline.
>That I would have to do over and over again until the
>length was right. Then I would have to divide the spline
>into a certain number of segments of equal length. And even
>then the bending of the neck wouldn't be very realistic.
>
>Instead of that I've tried to start with a spline, but then
>apply forces to each point so they will arrange correctly.
>
>See my message in povray.binaries.scene-files
>for the code I've done so far.
>
>I have succeeded in making the points having the right
>distance to each other:
>
>A force is applied to each point. If the point is closer to
>it's neighbor than the desired length then it is pushed
>away from it. If the point is further away the neighbor
>than the desired length then it is pulled closer to it.
>This calculation is done to each sphere with each of each
>sphere's two neighbors. The difference between the old
>and the new position is multiplied with a small value (*1),
>then stored in a temporary array. When the calculations are
>done to each sphere, the changes are applied. Then it
>starts all over and over again a certain number of times (*2).
>
>This makes the point have the right distance to each other,
>but nothing prevents the "neck" from bending so
>unfortunately the points arrange themselves in a zig-zag
>pattern.
>
>I need help with making some forces that makes the "neck"
>bend as little as possible, i.e. make the distribution of
>the bending even, that way making the curve smooth.
>(look in "ikn.inc" line 45.)
>
>I hope that you understand what I'm trying to do and that
>somebody might be able to help me...

Well, you can fix the zig-zag effect by ensuring that you always start
with a spline that's "outside" the curve that you finally end up with.
This causes the forces to all "pull" inwards.

E.g. in your example code, start with 

#declare _ikn_1 = vnormalize(ikn_v1)*_ikn_length*4+ikn_p1;
#declare _ikn_4 = vnormalize(ikn_v2)*_ikn_length*4+ikn_p2;
                                                ^^
instead of 

#declare _ikn_1 = vnormalize(ikn_v1)*_ikn_length/2+ikn_p1;
#declare _ikn_4 = vnormalize(ikn_v2)*_ikn_length/2+ikn_p2;

Unfortunately, if you start with a spline that's a long way "outside"
the curve you want, then it converges incredibly slowly. You can rack up
the ikn_pre value to about 0.5 to speed up the convergence (larger
values seem to cause strange effects), but you still need a higher value
of ikn_maxcalcs for good convergence. Some curves need much higher
maxcalc values than the particular example given in ikn.pov.

Unfortunately, also, there's nothing that restrains the first and last
links to remain oriented along the specified vector, and the "pull" from
the other links causes them to be drawn noticeably off line. (I guess
that if you tweak the code to restrain the first and last link, then
you'd get a kink at link 2 and link n-1.)

I also guess that the curve to which this converges is actually the same
shape as a spline, but with equidistant points. You say that a spline
doesn't give you a very realistic neck bend, but I reckon that that's
the shape you'll end up with if you ever get this working. It's fairly
easy to calculate the spline with the right total length (performing a
binary chop on the value I just tweaked above), but I can't see an easy
way to figure equidistant points. (You can't just start from the best
spline and perform your force calculations because in some parts of the
spline the points are too close together, so the forces push outwards
and cause a local zig-zag effect.) Perhaps you could calculate a spline
of the right length with, say, 10 or 20 times the number of points that
you need, then walk down the spline looking for the gap where the next
required point should fit.

-- 
Mike Williams #
Gentleman of Leisure


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.