 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Guest
|
Posted: Mon Nov 27, 2006 11:22 pm Post subject: Parallel Splines |
|
|
Hello,
I have to draw in 2D flexible pipes, or course they are not straight,
they follow spline curves.
drawing a gradient effect (to be closed to 3D view) would be the best
but probably too much complicated.
So if I could draw at least the spline with 2 colors (normal color in
the middle, darker in the border).
any idea of how to do this ? the splines must be at constant distance
from each other...
Thanks
John |
|
| Back to top |
|
 |
Bruce Larrabee Guest
|
Posted: Wed Nov 29, 2006 11:41 pm Post subject: Re: Parallel Splines |
|
|
Hello John,
Well this is how I do it... Sorry it's in C...
Hope there's enough here to get the idea...
HTH,
Bruce Larrabee
//---------------------------------------------------------------------------
//
// DrawOffset()
//
void DrawOffset( struct polyline *pline, double offset)
{
// given a pointer to a polyline (`pline'),
// create a line offset by an offset (`offset')...
int result;
double x1;
double y1;
double x2;
double y2;
double angle;
double next_angle;
struct line l1;
struct line *line1 = &l1;
struct line l2;
struct line *line2 = &l2;
struct point pt;
struct point *pnt = &pt;
struct vertex vi;
struct vertex *vinfo = &vi;
struct polyline *temp;
struct polyline *polyline_info = NULL;
if(pline == NULL)
{
return;
}
if(pline->base_vertex == NULL)
{
return;
}
vinfo = pline->base_vertex;
angle = 0.0;
next_angle = 0.0;
polyline_info = new_polyline( polyline_info);
polyline_info->base_vertex = NULL;
while(vinfo)
{
if(vinfo->next != NULL)
{
// all the line segments except the last...
if(vinfo->next->next == NULL)
{
// this is the end of the line...
break;
}
else
{
// get the relative angle for each end of the current
// line segment...
angle = angle_from_coordinates( vinfo->x, vinfo->y, vinfo->next->x, vinfo->next->y);
next_angle = angle_from_coordinates(
vinfo->next->x, vinfo->next->y,
vinfo->next->next->x, vinfo->next->next->y
);
}
// NOTE::
//
// Note that the line objects (line1 & line2)
// are loaded with the current x & y coordinates
// (vinfo->x & vinfo->y) of the start of the
// current line segment and the current x & y
// coordinates (vinfo->next->x & vinfo->next->y)
// of the end of the current line segment
// plus these same x and y coordinates
// offset 90 degrees multiplied by the distance
// that the new line is to be offset from
// the existing line (see code...)
// get the x and y coordinates offset 90 degrees
// from the start of the current line segment...
coordinates_from_angle( &x1, &y1, angle + 90);
// load the starting x and y coordinates to
// line 1 of the intersection test...
line1->sx = (vinfo->x + (x1 * offset));
line1->sy = (vinfo->y + (y1 * offset));
// load the ending x and y coordinates to
// line 1 of the intersection test...
line1->ex = (vinfo->next->x + (x1 * offset));
line1->ey = (vinfo->next->y + (y1 * offset));
// get the x and y coordinates offset 90 degrees
// from the end of the current line segment...
coordinates_from_angle( &x2, &y2, next_angle + 90);
// load the starting x and y coordinates to
// line 2 of the intersection test...
line2->sx = (vinfo->next->x + (x2 * offset));
line2->sy = (vinfo->next->y + (y2 * offset));
// load the ending x and y coordinates to
// line 2 of the intersection test...
line2->ex = (vinfo->next->next->x + (x2 * offset));
line2->ey = (vinfo->next->next->y + (y2 * offset));
// line_intersect_parametric()
//
// the following return values have these meanings...
//
// 0 - lines do in fact intersect...
//
// 3 - the lines EQUATIONS do in fact intersect, the lines don't...
//
// 1 - both line are the same...
//
// 2 - no intersect...
result = line_intersect_parametric_elevation( line1, line2, pnt);
if((result == 0)||(result == 3))
{
if(vinfo == pline->base_vertex)
{
// starting vertex...
polyline_info->base_vertex = AddVertex( line1->sx, line1->sy, vinfo->next->z, polyline_info);
}
polyline_info->end_vertex = AddVertex( pnt->x, pnt->y, vinfo->next->z, polyline_info);
vinfo = vinfo->next;
}
else
{
vinfo = vinfo->next;
}
}
}
polyline_info->end_vertex = AddVertex( line2->ex, line2->ey, vinfo->next->z, polyline_info);
AddPolyline( polyline_info);
}
//--------------------------------------------------------------------------- |
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Thu Nov 30, 2006 5:18 am Post subject: Re: Parallel Splines |
|
|
You cannot simply offset splines, just as you cannot simply offset beziers.
This is because the offset of a spline is *not* a spline, it can contain
sharp edges etcetera.
The best thing you can do is subdivide the splines in a smart way, cutting
them in little line segments, then offsetting these. You can then create
regions "middle" and "outer" by offsetting to both sides twice, and fill
these regions with standard methods (Canvas.Polygon).
Some good info on bezier subdivision can be found here:
http://www.antigrain.com/research/adaptive_bezier/index.html#PAGE_ADAPTIVE_BEZIER
For offsetting, google for "stroking" or "outlining" algorithm. I think the
other poster posted such an algorithm in c.
Nils
"John" <NoSpam (AT) NoSpam (DOT) com> schreef in bericht
news:456b1eca (AT) newsgroups (DOT) borland.com...
| Quote: | Hello,
I have to draw in 2D flexible pipes, or course they are not straight, they
follow spline curves.
drawing a gradient effect (to be closed to 3D view) would be the best but
probably too much complicated.
So if I could draw at least the spline with 2 colors (normal color in the
middle, darker in the border).
any idea of how to do this ? the splines must be at constant distance from
each other...
Thanks
John |
|
|
| Back to top |
|
 |
John Guest
|
Posted: Thu Nov 30, 2006 4:28 pm Post subject: Re: Parallel Splines |
|
|
Thanks All for your help.
The AGG sample is quite amazing. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|