POV-Ray : Newsgroups : povray.general : pipe_spline and color Server Time
23 Dec 2024 18:03:22 EST (-0500)
  pipe_spline and color (Message 1 to 9 of 9)  
From: Alex
Subject: pipe_spline and color
Date: 28 Nov 2015 05:50:00
Message: <web.565986946f420569f6cc3ced0@news.povray.org>
Hi everyone,

Is anybody experienced with Chris Colefax' spline package? I am trying to
generate a spline that changes its width and color along the spline position in
a controlled manner. The spline will be much longer that thick, so using spheres
seems like a bad option. Using "spline.mcr" and reading the tutorial I found
that I can create a spline using tubes (which is much more efficient that
spheres in my case) with the following syntax:

#declare my_spline = create_spline (
                             array[4] {start_position,  // 1st point
                                       start_position + start_direction,
                                       end_position - end_direction,
                                       end_position},   // 2rnd point
                                       create_bezier_spline)

#macro spline_radius_function () sClock #end
union { pipe_spline (my_spline, spline_radius (1)) pigment {rgb <1, 0, 0>} }

....with arbitrary parameters 'start_position', 'start_direction',
'end_position', and 'end_direction'. This gives me the right shape but a uniform
color. I have been trying to vary the color (linearly) along the spline by
multiplying the rgb value with 'sClock' or similar, but this is not accepted in
the syntax. Anybody done this before or knows a solution?

Many thanks in advance,
Alex


Post a reply to this message

From: Alain
Subject: Re: pipe_spline and color
Date: 28 Nov 2015 16:02:04
Message: <565a164c$1@news.povray.org>

> Hi everyone,
>
> Is anybody experienced with Chris Colefax' spline package? I am trying to
> generate a spline that changes its width and color along the spline position in
> a controlled manner. The spline will be much longer that thick, so using spheres
> seems like a bad option. Using "spline.mcr" and reading the tutorial I found
> that I can create a spline using tubes (which is much more efficient that
> spheres in my case) with the following syntax:
>
> #declare my_spline = create_spline (
>                               array[4] {start_position,  // 1st point
>                                         start_position + start_direction,
>                                         end_position - end_direction,
>                                         end_position},   // 2rnd point
>                                         create_bezier_spline)
>
> #macro spline_radius_function () sClock #end
> union { pipe_spline (my_spline, spline_radius (1)) pigment {rgb <1, 0, 0>} }
>
> ....with arbitrary parameters 'start_position', 'start_direction',
> 'end_position', and 'end_direction'. This gives me the right shape but a uniform
> color. I have been trying to vary the color (linearly) along the spline by
> multiplying the rgb value with 'sClock' or similar, but this is not accepted in
> the syntax. Anybody done this before or knows a solution?
>
> Many thanks in advance,
> Alex
>
>

You can use a gradient pattern. The only trick is orienting and scalling 
it properly.
For the direction, you use the difference between the start and end points.
For the scalling, you use the distance between those points.
That way, the zero entry of the colour_map will be at one point and the 
one at the other.
It can look like this:
gradient{
	abs(start_position-end_position)// direction vector
	colour_map{[0 rgb<1,0.5,0>][1 rgb<0,0,1>]}
	scale vlength(start_point-end_point)//make it fit
}

If your spline have an important curvature, it becomes more difficult. 
You'll need to find the approximate center of the curve and the covered 
angle. Then, using the radial pattern, use frequency and to adjust the 
colour_map to the angle of the curve, then translate the pattern to the 
center point.
This will involve a fair amount of trigonometry.


Alain


Post a reply to this message

From: Alex
Subject: Re: pipe_spline and color
Date: 28 Nov 2015 17:20:01
Message: <web.565a27fbe2db23c8f6cc3ced0@news.povray.org>
Hi Alain

Thanks for the solution you sketched. In principle, I am not afraid of extensive
trigonometry. However, this will mean that I am doing something that is very
simple in standard splines in a very elaborate way. My spline will indeed curve
substantially and, what's more, I will repeat the spline in a number of
geometries. If I follow your advice, I'll need to make it good enough to work in
general cases.

I was hoping that the spline package offers a one-line way to do this, and that
I simply missed the syntax. For instance, there is a spline clock term in the
package ("sClock"), but when I try utlilyzing it in the pigment definition, the
term is not accepted. Can it be that I have not understood how term has to be
defined?

Best regards,
Alex


Alain <kua### [at] videotronca> wrote:

> > Hi everyone,
> >
> > Is anybody experienced with Chris Colefax' spline package? I am trying to
> > generate a spline that changes its width and color along the spline position in
> > a controlled manner. The spline will be much longer that thick, so using spheres
> > seems like a bad option. Using "spline.mcr" and reading the tutorial I found
> > that I can create a spline using tubes (which is much more efficient that
> > spheres in my case) with the following syntax:
> >
> > #declare my_spline = create_spline (
> >                               array[4] {start_position,  // 1st point
> >                                         start_position + start_direction,
> >                                         end_position - end_direction,
> >                                         end_position},   // 2rnd point
> >                                         create_bezier_spline)
> >
> > #macro spline_radius_function () sClock #end
> > union { pipe_spline (my_spline, spline_radius (1)) pigment {rgb <1, 0, 0>} }
> >
> > ....with arbitrary parameters 'start_position', 'start_direction',
> > 'end_position', and 'end_direction'. This gives me the right shape but a uniform
> > color. I have been trying to vary the color (linearly) along the spline by
> > multiplying the rgb value with 'sClock' or similar, but this is not accepted in
> > the syntax. Anybody done this before or knows a solution?
> >
> > Many thanks in advance,
> > Alex
> >
> >
>
> You can use a gradient pattern. The only trick is orienting and scalling
> it properly.
> For the direction, you use the difference between the start and end points.
> For the scalling, you use the distance between those points.
> That way, the zero entry of the colour_map will be at one point and the
> one at the other.
> It can look like this:
> gradient{
>  abs(start_position-end_position)// direction vector
>  colour_map{[0 rgb<1,0.5,0>][1 rgb<0,0,1>]}
>  scale vlength(start_point-end_point)//make it fit
> }
>
> If your spline have an important curvature, it becomes more difficult.
> You'll need to find the approximate center of the curve and the covered
> angle. Then, using the radial pattern, use frequency and to adjust the
> colour_map to the angle of the curve, then translate the pattern to the
> center point.
> This will involve a fair amount of trigonometry.
>
>
> Alain


Post a reply to this message

From: Alain
Subject: Re: pipe_spline and color
Date: 28 Nov 2015 19:50:26
Message: <565a4bd2$1@news.povray.org>

> Hi Alain
>
> Thanks for the solution you sketched. In principle, I am not afraid of extensive
> trigonometry. However, this will mean that I am doing something that is very
> simple in standard splines in a very elaborate way. My spline will indeed curve
> substantially and, what's more, I will repeat the spline in a number of
> geometries. If I follow your advice, I'll need to make it good enough to work in
> general cases.
>
> I was hoping that the spline package offers a one-line way to do this, and that
> I simply missed the syntax. For instance, there is a spline clock term in the
> package ("sClock"), but when I try utlilyzing it in the pigment definition, the
> term is not accepted. Can it be that I have not understood how term has to be
> defined?
>
> Best regards,
> Alex
>
>

Usualy, any variable containing "clock", with any form of 
capitalisation, refer to the clock built in variable and is related to 
animations.
Most of the case, you'll find something like:
#declare sClock = clock*Something;
or
#declare sClock = clock*Something+SomethingElse;

It can also be set to some user defined value. When used with splines, 
it's usualy used to pick a specific point along the spline.


Post a reply to this message

From: Alex
Subject: Re: pipe_spline and color
Date: 29 Nov 2015 04:00:00
Message: <web.565abe3de2db23c8f6cc3ced0@news.povray.org>
Hi Alain,

That is precisely what I need. If I could make use of the length parameter along
the spline, I could define the pigment at every such position. In the short code
I posted, you can see in the #macro that the radius of my pipe_spline is defined
by the parameter sClock - the radius is proportional to the position along the
spline. I want to do the same thing for color, but it seems the parameter sClock
does not work there. I suspect that it would be possible if I invoked the
parameter correctly.

- Alex




Alain <kua### [at] videotronca> wrote:

> Usualy, any variable containing "clock", with any form of
> capitalisation, refer to the clock built in variable and is related to
> animations.
> Most of the case, you'll find something like:
> #declare sClock = clock*Something;
> or
> #declare sClock = clock*Something+SomethingElse;
>
> It can also be set to some user defined value. When used with splines,
> it's usualy used to pick a specific point along the spline.


Post a reply to this message

From: Alain
Subject: Re: pipe_spline and color
Date: 29 Nov 2015 17:39:57
Message: <565b7ebd@news.povray.org>

> Hi Alain,
>
> That is precisely what I need. If I could make use of the length parameter along
> the spline, I could define the pigment at every such position. In the short code
> I posted, you can see in the #macro that the radius of my pipe_spline is defined
> by the parameter sClock - the radius is proportional to the position along the
> spline. I want to do the same thing for color, but it seems the parameter sClock
> does not work there. I suspect that it would be possible if I invoked the
> parameter correctly.
>
> - Alex
>
>
>
>

You can have something like:
color_map{[0 rgb 1][sClock rgb<1,0,0>][1 rgb<0,1,1>]}

with the value of sClock previously declared, as long as sClock range 
from 0 to 1, both inclusive.

You may define additional splines that define your colours, say 
Colour_Spline. That way, you can use:

#declare Something = pigment{rgb Colour_Spline[sClock]}
or
#declare Something = pigment{rgbft<Red_Spline[sClock], 
Green_Spline[sClock], Blue_Spline[sClock], Filter_Spline[sClock], 
Transmit_Spline[sClock]}

Here, if sClock's value is outside the range of the spline, the result 
is taken at the nearest end.

Then, it's possible to construct a colour_map in a loop:

colour_map{
#declare Point = 0;
#while(Point <= 1)
  [Point rgb Colour_Spline[Point]]
#declare Point = Point + 0.01;
#end
}


Alain


Post a reply to this message

From: Thomas de Groot
Subject: Re: pipe_spline and color
Date: 30 Nov 2015 02:51:39
Message: <565c000b$1@news.povray.org>
On 29-11-2015 23:41, Alain wrote:

>> Hi Alain,
>>
>> That is precisely what I need. If I could make use of the length
>> parameter along
>> the spline, I could define the pigment at every such position. In the
>> short code
>> I posted, you can see in the #macro that the radius of my pipe_spline
>> is defined
>> by the parameter sClock - the radius is proportional to the position
>> along the
>> spline. I want to do the same thing for color, but it seems the
>> parameter sClock
>> does not work there. I suspect that it would be possible if I invoked the
>> parameter correctly.
>>
>> - Alex
>>
>>
>>
>>
>
> You can have something like:
> color_map{[0 rgb 1][sClock rgb<1,0,0>][1 rgb<0,1,1>]}
>
> with the value of sClock previously declared, as long as sClock range
> from 0 to 1, both inclusive.
>
> You may define additional splines that define your colours, say
> Colour_Spline. That way, you can use:
>
> #declare Something = pigment{rgb Colour_Spline[sClock]}
> or
> #declare Something = pigment{rgbft<Red_Spline[sClock],
> Green_Spline[sClock], Blue_Spline[sClock], Filter_Spline[sClock],
> Transmit_Spline[sClock]}
>
> Here, if sClock's value is outside the range of the spline, the result
> is taken at the nearest end.
>
> Then, it's possible to construct a colour_map in a loop:
>
> colour_map{
> #declare Point = 0;
> #while(Point <= 1)
>   [Point rgb Colour_Spline[Point]]
> #declare Point = Point + 0.01;
> #end
> }
>

Or, for a more aesthetic form ;-)

colour_map {
#for (Point, 0, 1, 0.01)
   [Point rgb Colour_Spline[Point]
#end
}


-- 
Thomas


Post a reply to this message

From: Alex
Subject: Re: pipe_spline and color
Date: 30 Nov 2015 15:35:01
Message: <web.565cb229e2db23c8f6cc3ced0@news.povray.org>
Thanks, guys, I'll try that!
- Alex



Thomas de Groot <tho### [at] degrootorg> wrote:
> On 29-11-2015 23:41, Alain wrote:

> >> Hi Alain,
> >>
> >> That is precisely what I need. If I could make use of the length
> >> parameter along
> >> the spline, I could define the pigment at every such position. In the
> >> short code
> >> I posted, you can see in the #macro that the radius of my pipe_spline
> >> is defined
> >> by the parameter sClock - the radius is proportional to the position
> >> along the
> >> spline. I want to do the same thing for color, but it seems the
> >> parameter sClock
> >> does not work there. I suspect that it would be possible if I invoked the
> >> parameter correctly.
> >>
> >> - Alex
> >>
> >>
> >>
> >>
> >
> > You can have something like:
> > color_map{[0 rgb 1][sClock rgb<1,0,0>][1 rgb<0,1,1>]}
> >
> > with the value of sClock previously declared, as long as sClock range
> > from 0 to 1, both inclusive.
> >
> > You may define additional splines that define your colours, say
> > Colour_Spline. That way, you can use:
> >
> > #declare Something = pigment{rgb Colour_Spline[sClock]}
> > or
> > #declare Something = pigment{rgbft<Red_Spline[sClock],
> > Green_Spline[sClock], Blue_Spline[sClock], Filter_Spline[sClock],
> > Transmit_Spline[sClock]}
> >
> > Here, if sClock's value is outside the range of the spline, the result
> > is taken at the nearest end.
> >
> > Then, it's possible to construct a colour_map in a loop:
> >
> > colour_map{
> > #declare Point = 0;
> > #while(Point <= 1)
> >   [Point rgb Colour_Spline[Point]]
> > #declare Point = Point + 0.01;
> > #end
> > }
> >
>
> Or, for a more aesthetic form ;-)
>
> colour_map {
> #for (Point, 0, 1, 0.01)
>    [Point rgb Colour_Spline[Point]
> #end
> }
>
>
> --
> Thomas


Post a reply to this message

From: Le Forgeron
Subject: Re: pipe_spline and color
Date: 1 Dec 2015 07:18:42
Message: <565d9022$1@news.povray.org>
Le 28/11/2015 11:48, Alex a écrit :
> Hi everyone,
>
> Is anybody experienced with Chris Colefax' spline package? I am trying to
> generate a spline that changes its width and color along the spline position in
> a controlled manner. The spline will be much longer that thick, so using spheres
> seems like a bad option. Using "spline.mcr" and reading the tutorial I found
> that I can create a spline using tubes (which is much more efficient that
> spheres in my case) with the following syntax:
>
> #declare my_spline = create_spline (
>                               array[4] {start_position,  // 1st point
>                                         start_position + start_direction,
>                                         end_position - end_direction,
>                                         end_position},   // 2rnd point
>                                         create_bezier_spline)
>
> #macro spline_radius_function () sClock #end
> union { pipe_spline (my_spline, spline_radius (1)) pigment {rgb <1, 0, 0>} }
>
> ....with arbitrary parameters 'start_position', 'start_direction',
> 'end_position', and 'end_direction'. This gives me the right shape but a uniform
> color. I have been trying to vary the color (linearly) along the spline by
> multiplying the rgb value with 'sClock' or similar, but this is not accepted in
> the syntax. Anybody done this before or knows a solution?
>
> Many thanks in advance,
> Alex
>
>
Have you considered sphere_sweep ?
There is even a patched version of povray 3.7 with support of UV-mapping 
on sphere_sweep (despite the lack of documentation about that)

( http://wiki.povray.org/content/User:Le_Forgeron , master head on 
either listed repository )

Otherwise, without uv-mapping, you are to immerse the shape in the 
patterned pigment. for simple variation and simple shape, it might be 
possible to pattern the pigment.


Post a reply to this message

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