# Board index » delphi » How to reduce a polyline points array...

## How to reduce a polyline points array...

hi,

Given a polyline with a large amount of line segments.  How I can reduce the
segments that will lay in a straight line?
Example for 2D: (This is what I am trying to do)
if Prev_Point.X = Next_Point.X or Prev_Point.Y = Next_Point.Y then // check
if this point is part of a large horizontal or vertical segment
begin
Current_Point := Next_Point;
WritePoint:= False; //do not write this point
end;
if not WritePoint then
if Prev_Point_Angle = Next_Point_Angle then // check if this point is
part of large diagonal segment
begin
Current_Point_Angle:= Next_Point_Angle;
WritePoint:= False;
end;
Any Help really appreciated;

Abraham.

## Re:How to reduce a polyline points array...

Have a look at my component (not free):
http://www.simdesign.nl/bezier.html

Kind regards,

Nils Haeck
www.simdesign.nl

##### Quote
"Abraham Valdes" wrote...
> hi,

> Given a polyline with a large amount of line segments.  How I can reduce
the
> segments that will lay in a straight line?
> Example for 2D: (This is what I am trying to do)
> if Prev_Point.X = Next_Point.X or Prev_Point.Y = Next_Point.Y then //
check
> if this point is part of a large horizontal or vertical segment
>   begin
>   Current_Point := Next_Point;
>   WritePoint:= False; //do not write this point
>  end;
> if not WritePoint then
>    if Prev_Point_Angle = Next_Point_Angle then // check if this point is
> part of large diagonal segment
>     begin
>      Current_Point_Angle:= Next_Point_Angle;
>      WritePoint:= False;
>    end;
> Any Help really appreciated;

> Abraham.

## Re:How to reduce a polyline points array...

Parametric equation of line in 3D
x=ax*t+bx
y=ay*t+by
z=az*t+bz

find a and b coefficients for 1st segment

check t for the next line endpoint ( t=(xnext-bx)/ax )

parameter t must be equal for x, y and z (+- some tolerance)

extra case:
if, for example, ax=0, xnext must be = bx

--
Regards
Boris Novgorodov

##### Quote
> Given a polyline with a large amount of line segments.  How I can reduce
the
> segments that will lay in a straight line?