POV-Ray : Newsgroups : povray.advanced-users : Adding forces to points in curves Server Time
26 Dec 2024 01:29:41 EST (-0500)
  Adding forces to points in curves (Message 1 to 10 of 17)  
Goto Latest 10 Messages Next 7 Messages >>>
From: Rune
Subject: Adding forces to points in curves
Date: 27 Dec 1999 17:02:57
Message: <3867e211@news.povray.org>
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...

Thanks,

Rune

---
Updated December 22: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!


Post a reply to this message

From: Peter Popov
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 02:08:56
Message: <CGBoOOdUOOkiEl4Ur8e3MSw5urkS@4ax.com>
Rune,

this is an interesting approach. As far as I understand your problem
is that when the points start repelling each other, they leave the
spline, right? So how about tweaking this idea a bit? The spline is a
function with one parameter, let's name it time or t (well, the
control points and vectors are technically also parameter but they are
the same for all points so I won't consider them here). For every t
there is an unique point on the spline. What you have to do is store
an array of the values of t of the points on the spline. When you
calculate the forces and the displacement they cause, apply this
displacement along the t axis and not x,y or z. Then you'll know for
sure that no whatever the points ditribution, the spline shape will
remain constant. Do this until no force is greater than a certain
threshold value or even better, the standard deviation of the forces
falls below a certain level (i.e. the spline is equistressed). It
would look cool animated, too, especially if the spline moves at the
same time.

I hope I explained my idea well and that it is actually od some help.
I haven't tested it but it seems like it will work. Good luck and
don't hesitate to ask if there's something wrong. I am also interested
in this problem but being the lazy bum that I am I'd rather stay aside
and give advice and let others do it :)))


Peter Popov
pet### [at] usanet
ICQ: 15002700


Post a reply to this message

From: Mike Williams
Subject: Re: Adding forces to points in curves
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

From: Gilles Tran
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 04:11:48
Message: <38687EE0.EA9978BD@inapg.inra.fr>
Perhaps this could give you ideas (if you don't already know Hugo Elias'
site of course)
http://freespace.virgin.net/hugo.elias/models/m_string.htm
G.

Rune wrote:

> 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] )
>


Post a reply to this message

From: Rune
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 17:39:58
Message: <38693c3e@news.povray.org>
Gilles Tran wrote:
>Perhaps this could give you ideas (if you don't already
>know Hugo Elias' site of course)
>http://freespace.virgin.net/hugo.elias/models/m_string.htm

I knew his site but hadn't had a close look at that page in particular.
It seems though that what he explains is what I had already done.
Thanks for the reply anyway!

Greetings,

Rune

---
Updated December 22: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!


Post a reply to this message

From: Rune
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 17:40:00
Message: <38693c40@news.povray.org>
Peter Popov wrote:
>this is an interesting approach. As far as I understand your problem
>is that when the points start repelling each other, they leave the
>spline, right?

Actually not. The idea was to use forces to change the spline so it would
get the right length, have more smooth bending, and to get equidistant
points.

However, I've now dropped this idea. Instead I want to calculate the spline
with the right length and then use your method to get equidistant points on
that spline. (See my reply to Mike Williams.)

>For every t
>there is an unique point on the spline. What you have to do is store
>an array of the values of t of the points on the spline. When you
>calculate the forces and the displacement they cause, apply this
>displacement along the t axis and not x,y or z. Then you'll know for
>sure that no whatever the points ditribution, the spline shape will
>remain constant.

I understand this.

However, I'm not sure what the difference is between this:

>Do this until no force is greater than a certain threshold value

...and this:

>or even better, the standard deviation of the forces
>falls below a certain level (i.e. the spline is equistressed).

But I guess that's not so important anyway. I get the basic idea.

Greetings,

Rune

---
Updated December 22: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!


Post a reply to this message

From: Rune
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 17:40:01
Message: <38693c41@news.povray.org>
Mike Williams wrote:
>Wasn't it Rune who wrote:

>>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] )

>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.)

Yes, that's a problem.

>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.

OK, I'll drop my original idea about adding forces to points in a spline.


Instead I'll calculate the spline with the right total length and then try
to use Peter Popov's method to figure equidistant points.

However, I don't know yet how to calculate the spline with the right total
length.

>It's fairly easy to calculate the spline with the right total
>length (performing a binary chop on the value I just tweaked above),

Could you explain this in greater detail?

Greetings,

Rune

---
Updated December 22: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!


Post a reply to this message

From: Kevin Wampler
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 18:10:14
Message: <389221EC.742F2771@tapestry.tucson.az.us>
This is a quite interesting problem.  I have an idea, but I haven't
tested it so I don't know how well it would work.  Once you have a
spline of the right length, you can use Peter Popov's method to place
the points equally along it, so the problem, as you said, is finding a
spline of the correct length.  My idea is that you could take your
starting spline and calculate its total length (using an approximating
sum).  Then take how this sum compares to the desired length, you could
then move the control points toward or away from the line connecting the
endpoints of the spline and repeat the process until the spline has a
length that is close enough to what you want.  The advantage of this
method is that you can change exactly how the control points are moved
to get an effect more like what you are looking for.


Post a reply to this message

From: Peter Popov
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 18:52:46
Message: <JUxpOHq5JBLmX7HJHf1aepoeQp5l@4ax.com>
On Tue, 28 Dec 1999 23:33:16 +0100, "Rune" <run### [at] inamecom>
wrote:

>However, I'm not sure what the difference is between this:
>
>>Do this until no force is greater than a certain threshold value
>
>...and this:
>
>>or even better, the standard deviation of the forces
>>falls below a certain level (i.e. the spline is equistressed).

The difference is that if you have too many points, the forces between
them may be great but still equal, which would force the first
algorithm into an infinite loop, while the second (which looks at the
deviation) will stop seeing that all forces are virtually equal.

>But I guess that's not so important anyway. I get the basic idea.

For once I was able to make a clear point :)

>Greetings,
>
>Rune


Peter Popov
pet### [at] usanet
ICQ: 15002700


Post a reply to this message

From: Chris Colefax
Subject: Re: Adding forces to points in curves
Date: 28 Dec 1999 19:05:34
Message: <3869504e@news.povray.org>
Rune <run### [at] inamecom> wrote:
> 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] )
[snip]
> 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.)

To avoid confusion I think it helps to use the word 'tangent' when you're
talking about a vector tangential to the curve, particularly as 'normal' has
particular meanings in POV-Ray (and, of course, in any discussions about
mathematical curves and surfaces).

Now, given the example you posted to .binaries and your description of your
goal I would say the method you're using (inverse kinematics) is quite
suitable.  To avoid kinking perhaps you could apply an extra constraint to
each link which checks the angle it forms with the links around it, eg.
given three sphere centres (P1, P2, and P3) you could calculate the cosine
of the angle using:

   vdot (vnormalize (P2 - P1), vnormalize (P3 - P2))

To stop the kinking you want this to be as close as possible to -1 (the
cosine of 180 degrees), so in addition to being pulled by the endpoints and
tangents and being forced to be separated by a certain distance, the spheres
also try to form a straight line (or as close as possible given the other
constraints).


Post a reply to this message

Goto Latest 10 Messages Next 7 Messages >>>

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