POV-Ray : Newsgroups : povray.general : Rotating an object so it is tangent to a spline. Server Time
26 Nov 2024 03:52:50 EST (-0500)
  Rotating an object so it is tangent to a spline. (Message 1 to 5 of 5)  
From: D103
Subject: Rotating an object so it is tangent to a spline.
Date: 13 Oct 2011 10:55:00
Message: <web.4e96fac5c8ea8b465ae2687f0@news.povray.org>
Hello,
I am making a very basic test animation of a cannon shell being fired from a
gun.
After a bit of fiddling around, I have sorted out the path of the shell, and can
do pretty much anything I want with it.

However I have not figured out how to rotate it so that it is always tangent to
it's path.

I have written another "still" scene where the path is defined by a spline, but
the
closest I could get to a tangent was this:

#declare S=1;
#declare N=80;
#declare C=0;
#declare A=45;   //firing angle; in animated scene it is defined otherwise.
#declare AR=radians(A);
#declare V=100;  //muzzle velocity m/sec
#declare G=10;   //gravity m/sec, rounded up for simplicity


#declare Path1 = spline {
  linear_spline
  #while(S<=N)
    #declare XV = (sin(radians(90.0)-AR)*V*C);
    #declare YV = (sin(AR)*V*C-G*pow(C,2));
    S/N, <XV, YV, 0>
    #declare S=S+1;
    #declare C=C+0.1;
  #end
}

#declare Cnt=1;
#declare Max=20;

sphere_sweep {
  linear_spline Max
  #while(Cnt<=Max)
    #declare Point = Parabola1((Cnt-1)/(Max-1));
    Point, 0.5
    #declare Cnt=Cnt+1;
  #end
  pigment { Blue }
  translate x*-250
  scale 1/25
}

#declare P = 0.0;

cylinder {
  x*50, x*-50, 1
  pigment { Green }
  rotate x*(A-(2*P*A)      //this rotates the cylinder depending on its position
  translate Path1(P)
  translate x*-250
  scale 1/25
}

While this doesn't look too bad for 45 degrees, any higher or lower and the fact
that it is not tangent becomes apparent.

I have looked at math.inc, and I think that VAngle() and VRotation(), or some of
the Vector Analysis macros might be what I'm looking for, but how to get a
usable value from them is currently beyond my mathematical capabilities.

If I've made anything unnecessarily complex, which is often the case, :-(
could someone point me in the right direction?

Otherwise it looks like I'm in for some fairly complicated math.

D103


Post a reply to this message

From: Le Forgeron
Subject: Re: Rotating an object so it is tangent to a spline.
Date: 13 Oct 2011 14:13:24
Message: <4e972a44@news.povray.org>
Le 13/10/2011 16:52, D103 nous fit lire :
> Hello,
> I am making a very basic test animation of a cannon shell being fired from a
> gun.
> After a bit of fiddling around, I have sorted out the path of the shell, and can
> do pretty much anything I want with it.
> 
> However I have not figured out how to rotate it so that it is always tangent to
> it's path.
> 
> I have written another "still" scene where the path is defined by a spline, but
> the
> closest I could get to a tangent was this:

what about creating the cylinder at the right position & orientation
first ? (instead of creating it and moving it)

tangent to spline Path1 at P is something like looking at P+epsilon.

#local CurPoint=Path1(P);
#local Soon=Path1(P+epsilon);
cylinder { CurPoint+50*vnormalize(Soon-CurPoint),
           CurPoint+50*vnormalize(CurPoint-Soon), 1
...

(assuming you want the center of cylinder on spline)


Post a reply to this message

From: Cousin Ricky
Subject: Re: Rotating an object so it is tangent to a spline.
Date: 13 Oct 2011 21:20:00
Message: <web.4e978d143f98dc0e78641e0c0@news.povray.org>
"D103" <nomail@nomail> wrote:
> #declare G=10;   //gravity m/sec, rounded up for simplicity

That should be m/sec^2.


Post a reply to this message

From: D103
Subject: Re: Rotating an object so it is tangent to a spline.
Date: 14 Oct 2011 00:10:01
Message: <web.4e97b4fd3f98dc0e5ae2687f0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
>
> what about creating the cylinder at the right position & orientation
> first ? (instead of creating it and moving it)
>
> tangent to spline Path1 at P is something like looking at P+epsilon.
>
> #local CurPoint=Path1(P);
> #local Soon=Path1(P+epsilon);
> cylinder { CurPoint+50*vnormalize(Soon-CurPoint),
>            CurPoint+50*vnormalize(CurPoint-Soon), 1
> ...
>
> (assuming you want the center of cylinder on spline)

Thanks very much, I have tried this and I think that with a little tweaking it
will meet all of my requirements for both test scenes, and the animation as
well.

I think I will retain the use of a spline as well, as it will allow me to have
several shells in the air at the same time, especially with a shell flight time
of ~24 seconds.

Many thanks,
D103


Post a reply to this message

From: D103
Subject: Re: Rotating an object so it is tangent to a spline.
Date: 14 Oct 2011 00:15:01
Message: <web.4e97b6193f98dc0e5ae2687f0@news.povray.org>
"Cousin Ricky" <rickysttATyahooDOTcom> wrote:
> "D103" <nomail@nomail> wrote:
> > #declare G=10;   //gravity m/sec, rounded up for simplicity
>
> That should be m/sec^2.

Ah yes, so it should. Thankfully it's just an error in the notes, gravity is
calculated properly here:
>     #declare YV = (sin(AR)*V*C-G*pow(C,2));
Thanks anyway, :-)
D103


Post a reply to this message

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