POV-Ray : Newsgroups : povray.general : pipe_spline and color : Re: pipe_spline and color Server Time
3 Jul 2024 03:29:42 EDT (-0400)
  Re: pipe_spline and color  
From: Alain
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

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