POV-Ray : Newsgroups : povray.general : Curved line Server Time
4 Nov 2024 23:21:07 EST (-0500)
  Curved line (Message 1 to 9 of 9)  
From: twister
Subject: Curved line
Date: 18 Feb 2009 07:15:00
Message: <web.499bfb71fb5d997a8896485d0@news.povray.org>
Hi,

Is it possible to draw a line connecting a few points using spline feature? In
fact I need a smooth ribbon (the line is the center line of that ribbon) but
not in all directions - just in one plane (x-z). I have tried using prisms but
I have problems with constant width of that shape along whole length.
Let me know how it can be made - just some clue.
Thanks in advance.

Twister


Post a reply to this message

From: twister
Subject: Re: Curved line
Date: 18 Feb 2009 09:40:00
Message: <web.499c1d784c7fcf678896485d0@news.povray.org>
Of course if something is unclear, let me know...


Post a reply to this message

From: Chris B
Subject: Re: Curved line
Date: 18 Feb 2009 10:27:56
Message: <499c28fc$1@news.povray.org>
"twister" <twi### [at] o2pl> wrote in message 
news:web.499c1d784c7fcf678896485d0@news.povray.org...
>
> Is it possible to draw a line connecting a few points using spline 
> feature? In
> fact I need a smooth ribbon (the line is the center line of that ribbon) 
> but
> not in all directions - just in one plane (x-z). I have tried using prisms 
> but
> I have problems with constant width of that shape along whole length.
> Let me know how it can be made - just some clue.
> Thanks in advance.
>
> Of course if something is unclear, let me know...
>

Your description is a little unclear to me but ...

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.

Regards,
Chris B.


Post a reply to this message

From: twister
Subject: Re: Curved line
Date: 18 Feb 2009 11:00:00
Message: <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?

Regards,
Twister


Post a reply to this message

From: Chris B
Subject: Re: Curved line
Date: 18 Feb 2009 13:41:00
Message: <499c563c@news.povray.org>
"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

From: twister
Subject: Re: Curved line
Date: 19 Feb 2009 06:45:01
Message: <web.499d45114c7fcf678896485d0@news.povray.org>
Thanks Chris!

I find the prism model more accurate for my purposes. I also think of marking
the points at specific length of spline. For example if spline has overall
length of 32.1 units I would like to find a point where the length is 10. Is
there any functions which provide such information?

Best regards,
Twister


Post a reply to this message

From: Chris B
Subject: Re: Curved line
Date: 19 Feb 2009 09:20:12
Message: <499d6a9c$1@news.povray.org>
"twister" <twi### [at] o2pl> wrote in message 
news:web.499d45114c7fcf678896485d0@news.povray.org...
> Thanks Chris!
>
> I find the prism model more accurate for my purposes. I also think of 
> marking
> the points at specific length of spline. For example if spline has overall
> length of 32.1 units I would like to find a point where the length is 10. 
> Is
> there any functions which provide such information?
>
> Best regards,
> Twister
>

Someone might have an existing macro, otherwise you can just loop through 
using the vlength function to calculate a cumulative spline length and add 
some logic to detect specific distances along the spline. The following 
example plugs into the example I gave before, so I've used a distance of 2 
rather than 10 (my spline wasn't 10 units long).

Regards,
Chris B.

// Initialise some variables.
#declare PreviousPosition = MySpline(0);
#declare I = 0.01;
#declare CumulativeLength = 0;
// Loop through the spline keeping account of the length
#while (I < 1)
  #declare ThisPosition = MySpline(I);
  #declare CumulativeLength = 
CumulativeLength+vlength(ThisPosition-PreviousPosition);
  // If we didn't reach 2 units before, but we reached it now, record the 
location.
  #ifndef(Position_2)
    #if (CumulativeLength>2) #declare Position_2 = ThisPosition; #end
  #end
  // Get ready for the next iteration of the loop
  #declare PreviousPosition = ThisPosition;
  #declare I = I + 0.01;
#end

// Add a sphere and write the location into the message stream.
#ifdef (Position_2)
  sphere {Position_2,0.1 pigment {rgb <1,0,0>}}
  #debug concat("Position_10: ",vstr(3,Position_2,",",3,3),"\n")
#end


Post a reply to this message

From: twister
Subject: Re: Curved line
Date: 20 Feb 2009 06:15:11
Message: <web.499e8fba4c7fcf678896485d0@news.povray.org>
I have noticed that when I use shapes (with splines according to your macro)
that are curved much and width of 'road' is big enough, there are some holes in
the output shape. Some kind of intersection must occur then. Is there any
solution for that?

Best regards,
Twister


Post a reply to this message

From: Chris B
Subject: Re: Curved line
Date: 20 Feb 2009 07:53:43
Message: <499ea7d7$1@news.povray.org>
"twister" <twi### [at] o2pl> wrote in message 
news:web.499e8fba4c7fcf678896485d0@news.povray.org...
>I have noticed that when I use shapes (with splines according to your 
>macro)
> that are curved much and width of 'road' is big enough, there are some 
> holes in
> the output shape. Some kind of intersection must occur then. Is there any
> solution for that?
>

Yes, if the radius of curvature of the spline is less than half the width of 
the road, then the inner edge of the curve effectively loops back on itself 
(the 'left' vectors from successive positions along the spline start to 
cross over each other). The prism object determines the inside and outside 
of the object based on the number of times you have to pass through the 
perimeter to get outside it, so POV-Ray thinks of these folds as being 
hollows within the main body of the prism.

In some specific cases it may help to adjust the number of slices used. I 
used 100. A far lower figure may help in certain cases, but the straight 
edges will become more visible and success in this would be very much down 
to luck.

If you want to do hairpin bends or Z shapes with neat creases then you'll 
have to make sure that the radius of curvature of the central spline is 
never less than half the width of the 'road'. If you only get these tight 
curves on one side of the 'road', you could achieve this by adjusting the 
technique to follow a spline that defines that edge of the 'road' on the 
'outward' journey and a line that is displaced by twice as much on the 
'return' journey.

The other technique, using a union of spheres (or vertical cylinders) to 
follow the line of the spline, doesn't suffer from this problem. If you find 
it isn't smooth enough for your needs you could simply increase the number 
of spheres/cylinders until it is.

Regards,
Chris B.


Post a reply to this message

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