|
|
I have two questions I hope someone here can help me with. I have a path
given by an array of vectors. For example:
#declare path1_num = 5; //number of points used to define spline
(one more then the number of segments)
#declare path1 = array[path1_num][3]
{
{<0,0,0>,<0,0,1>,<0,1,0>}, //first point of spline,
//forward for first segment of spline,
//up for first segment of spline
{<0,0,10>,<1,0,0>,<0,1,0>}, //second point of spline,
//forward for second segment of spline,
//up for second segment of spline
{<20,0,10>,<0,0,1>,<0,1,0>}, //third point of spline,
//forward for third segment of spline,
//up for third segment of spline
{<20,0,40>,<-1,0,0>,<0,1,0>}, //forth point of spline,
//forward for last segment of spline,
//up for last segment of spline
{<10,0,40>,<-1,0,0>,<0,1,0>} //last point of spline,
//forward at end of spline,
//up at end of spline
};
First question, assume the path is confined to the y=0 plane as above with
90 degree turns. I want a prism that will draw that path with some width.
For example, for the above path that prism could be:
#declare path1_sides = prism {
linear_sweep
linear_spline
0, // sweep the following shape from here ...
2, // ... up through here
11, // the number of points making up the shape ...
<0.1,0>,
<0.1,9.9>,
<20.1,9.9>,
<20.1,40.1>,
<10.0,40.1>,
<10.0,39.9>,
<19.9,39.9>,
<19.9,10.1>,
<-0.1,10.1>,
<-0.1,0>
<0.1,0>
}
Now given a general array/path like the above I think it should be possible
to write a macro that will generate the prism, however its proving to be
alot harder then I think it should be. Anyone here got an idea or some
simple code that will do the above?
Second question... let's relax the requirement that the path be in the y=0
plane. Take this path for example:
#declare path1 = array[path1_num][3]
{
{<0,0,0>,<0,0,1>,<0,1,0>}, //first point of spline,
//forward for first segment of spline,
//up for first segment of spline
{<0,0,1>,<1,0,0>,<0,1,0>}, //second point of spline,
//forward for second segment of spline,
//up for second segment of spline
{<2,0,1>,<0,1,0>,<-1,0,0>}, //third point of spline,
//forward for third segment of spline,
//up for third segment of spline
{<2,3,1>,<0,0,1>,<-1,0,0>}, //forth point of spline,
//forward for last segment of spline,
//up for last segment of spline
{<2,3,5>,<0,0,1>,<-1,0,0>} //last point of spline,
//forward at end of spline,
//up at end of spline
};
Now assume the above array just contained the vectors defining the points of
the spline. I know the difference in two consecutive points can be used to
define a "forward" for any segment of the spline, but is there an easy way
to know what the "up" vector should be for a given segment given the
initial "up". Again assume just 90 degree turns. Left and Right turns
don't change the "up" vector. For Down turns or dives, the "up" vector
becomes the "forward" vector of the previous segmant. For Up turns or
climbs, the "up" vector becomes the negative of the "forward" vector of the
previous segmant. So in short I'm trying to create a macro which will
create the above array given:
1. The number of points used to define the path. Call it "x".
2. The 1D array of those points call it path[x].
3. The initial "up" vector. Call it up[1].
All the "forward" and the remainder if the "up" vectors should follow from
the above.
Thanks,
Carl
Post a reply to this message
|
|