POV-Ray : Newsgroups : povray.general : How would I do this? : Re: How would I do this? Server Time
3 Aug 2024 08:11:40 EDT (-0400)
  Re: How would I do this?  
From: Tyler Eaves
Date: 24 Mar 2004 10:10:54
Message: <pan.2004.03.24.15.12.50.425564@NOSPAMml1.net>
On Tue, 23 Mar 2004 21:28:58 -0500, Tyler Eaves wrote:

> Okay, I've got a vector math question for those of you who are good with
> that kinda stuff.....
> 
> Here's the setup. Imagine a spline describing a 3D curve with undulations,
> rather like, say, a roller coaster track. (Indeed, that is exactly what I
> intend to do with it.) I want to be able to translate a point relative to
> the origin 'along' the spline, so that basically the Z-axis at the origin
> would point along the tangent of the spine at the point. Now the tricky
> part. I want to *twist* the spline, with a another 1d spline that
> represents the twist in degrees at any given point.

Well, with some various ideas, I've worked out a way to handle it without
using Spline_Trans. Still not as fast as I'd like, but it works, kinda.
Except that if the track comes back along the -z axis, the banking goes
crazy.

180 turn - problems: http://tylere.com/coaster1.png
90 turn - no problems: http://tylere.com/coaster2.png
270 turn - problem at the 180o point: http://tylere.com/coaster3.png


Here's the code I've hacked up:

#include "transforms.inc"
camera{location <100,60,-100> look_at <100,0,50>}
light_source{<0,200,-400>,1}
plane{y,-25 pigment{rgb <0,1,0>}}
#declare track = spline{
  natural_spline
  -1, <0,60,-1>
  0, <0,60,0>
  100, <0,60,100>
  200, <50,20,150>
  300, <100,5,100>
  400, <100,5,-50>
}
#declare banking = spline{
  linear_spline
  0,0
  100,0
  200,-60
  300,-70
 


  400, 0
}
#declare p = -1;
#declare last = transform{rotate <0,0,banking(p).x>
Reorient_Trans(<0,0,1>,vnormalize(track(p+.5)-track(p))) translate track(p)};
#declare s = 0;
#declare p = 0;
#while (p < 400)
  #declare vec = vnormalize((track(p+.5)+<0,.01,0>)-track(p)); 
   #declare trans = transform{rotate <0,0,banking(p).x>
Reorient_Trans(<0,0,1>,vnormalize((track(p+.5)+<0,.01,0>)-track(p))) translate
track(p)};
  union{
  cylinder{vtransform(<-2,-4,0>,trans),vtransform(<-2,-4,0>,last),.25}
  cylinder{vtransform(<2,-4,0>,trans),vtransform(<2,-4,0>,last),.25}
  cylinder{vtransform(<-2,-4,0>,trans),vtransform(<2,-4,0>,trans),.2}
  pigment{rgb <0,0,1>}
  }
  #declare s = s + 1;
  #if (s > 10)
    #declare s = 0;
    cylinder{vtransform(<0,-8,0>,trans),
vtransform(<0,-8,0>,trans)-<0,vtransform(<0,-8,0>,trans).y + 25,0>,.5 pigment{rgb 1}}
    cone{vtransform(<0,-8,0>,trans),.5, vtransform(<0,-4,0>,trans),.2 pigment{rgb
<0,0,1>}}
  #end
  #debug concat(str(p,0,0)," - ",str(banking(p).x,0,2),"\n")
  #debug concat(str(vec.x,0,1),",",str(vec.y,0,1),",",str(vec.z,0,1),"\n")  
  #declare last = trans;
  #declare p = p + 3;
#end


Post a reply to this message

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