|
|
"twister" <twi### [at] o2pl> wrote in message
news:web.499c2f4a4c7fcf678896485d0@news.povray.org...
> "Chris B" <nom### [at] nomailcom> wrote:
>> I imagine that you are describing something lying flat on the XZ-plane
>> winding around like a track or a roadway or something like that?
>>
>> If that is what you want, then you could define the centre line as a
>> POV-Ray
>> spline, then generate a POV-Ray prism object that follows the line of the
>> spline with appropriate offsets to the left and right (to keep the width
>> constant). To do this you could build the prism using two #while loops.
>> The
>> first would follow the spline from 0 to 1 and offset to the left, the
>> second
>> would follow the spline back from 1 to 0, offsetting to the right.
>>
>> To offset from a spline you need to get the direction of the spline at
>> the
>> point you're interested in. You can do this using a point slightly ahead
>> of
>> or slightly behind the current position. You can then use the
>> VPerp_To_Plane
>> function from "math.inc" with the 'up' vector (y) to get a vector
>> pointing
>> out to the left (or right). Add this vector times a distance to the
>> current
>> position to get the new position that is offset from the spline.
>
> Yes, you're right! I want something that is quite like a road object with
> constant width and placed on X-Z plane.
> I tried to use prism, but it didn't work as required (probably something
> was
> wrong). I used a pair describing each point: point-coordinates and its
> vector
> of "movement". The vector allowed me to get side points that are in
> constant
> distance from center of line, but I still can't get smooth 'road'. Could
> you
> provide me some example as I am a bit new to povray or point some
> reference how
> to handle it?
>
The example below illustrates two alternative techniques. The first simply
draws a succession of spheres that follow the spline, then slices a thin
Yellow slice out of the middle. The second uses the technique I described
above, with two #while loops to create a prism that follows one side of a
spline up and the other side back (Orange). Note that the second #while
loop effectively runs backwards (from 100 to 0).
Regards,
Chris B.
camera {location <0,5,-3> look_at 0}
light_source {<30,70,-10> color rgb 1}
#include "math.inc"
#declare MyWidth = 0.6;
#declare MySpline = spline {
cubic_spline
-.25, <3,0,0.2>
0.00, <2,0,0.2>
0.25, <0,0,1>
0.50, <-2,0,0>
0.75, <-3,0,1>
1.00, <-3,0,2>
1.25, <-3,0,4>
}
difference {
union {
#declare I = 0;
#while (I < 1)
sphere {
MySpline(I),.15
}
#declare I = I + 0.01;
#end
}
plane { y,-0.01}
plane {-y,-0.01}
pigment { rgb <1,1,0> }
translate 0.5*y
}
prism {
linear_spline
0,0.5,202
#declare I = 0;
#while (I <= 100)
#declare ThisPosition = MySpline(I/100);
#declare AheadVector = MySpline((I+1)/100)-ThisPosition;
#declare LeftVector = vnormalize(VPerp_To_Plane(AheadVector,y));
#declare SidePosition = ThisPosition + LeftVector*MyWidth/2;
<SidePosition.x,SidePosition.z>
#declare I = I + 1;
#end
#declare I = 100;
#while (I >=0)
#declare ThisPosition = MySpline(I/100);
#declare AheadVector = MySpline((I+1)/100)-ThisPosition;
#declare LeftVector = vnormalize(VPerp_To_Plane(AheadVector,-y));
#declare SidePosition = ThisPosition + LeftVector*MyWidth/2;
<SidePosition.x,SidePosition.z>
#declare I = I - 1;
#end
pigment { rgb <1,0.1,0> }
}
Post a reply to this message
|
|