Board index » delphi » Line

Line


2003-10-04 01:28:56 AM
delphi260
hi,
I have a line that is created by X1, Y1, X2 and Y2.
I want now this line as a polygon, so that I get a polygon
that behaves like the line would have etc. a thick of 5 pixels.
I can easily make a polyline with the Start and End Point, but
how to make a polygon like I want ?
thanks a lot,
alex
 
 

Re:Line

Hi Alexander,
Given a general formula ax+by+c=0, if b<>0, the point-slope form is
y=-ax/b-c/b, so the vector is proportional to (-a/b,-1) which, multiplying
by -b, is proportional to (a,b).
Given a line of the form ax+by+c, b=0, we have the vector (1,0) which is
proportional to the vector (a,0)=(a,b). So, given ax+by+c=0, ax+by-c=0, or
ax+by=c style equations the vector is proportional to (a,b) regardless of
a and b.
Simply offset each of the end points of your original line by a sufficient
quantity of the normal.
You should now have a set of parallel lines ... connect their edges to get a
polygon.
Regards,
Ananth B.
"Alexander Adam" <XXXX@XXXXX.COM>writes
Quote
hi,

I have a line that is created by X1, Y1, X2 and Y2.
I want now this line as a polygon, so that I get a [snip]
 

Re:Line

I'm glad that you got the sense of his question..i must be very tired cause
i couldnt understand it at all
Quote
Regards,
Ananth B.

"Alexander Adam" <XXXX@XXXXX.COM>writes
news:3f7db0c1$XXXX@XXXXX.COM...
>hi,
>
>I have a line that is created by X1, Y1, X2 and Y2.
>I want now this line as a polygon, so that I get a [snip]


 

Re:Line

hi,
Quote
I'm glad that you got the sense of his question..i must be very tired
cause
i couldnt understand it at all
nah - I think its a bit more relying on the question itself, it was pretty
hard to
ask that, please don't mind me ;-)
Alex
 

Re:Line

hi,
Offseting doesn't help, e.g. when I have a horizontal or vertical line...
What to do ?
alex
 

Re:Line

Hi Alexander,
Offset the endpoints of the line along the normal's direction. You will
get two parallel lines.
Lets take the vertical line case ...
with line equation x - 1 = 0;
a = 1 and b = 0, so the normals here would be (1, 0) or (-1, 0).
Lets choose (1, 0)
newX1 = oldX1 + 1;
newY1 = oldY1 + 0;
the x coordinate just got shifted to the left now.
Do the same for X2, Y2 ... we have 2 parallel lines (new line lies to the
left of the old line).
now connecting oldX1 to newX1 etc etc ... we get a rectangle of a certain
thickness. The thickness can be adjusted by scaling the normal
(ex: for half the width you scale it by 0.5 so the new line gets offseted
only by 0.5 units)
Regards,
Ananth B.
"Alexander Adam" <XXXX@XXXXX.COM>writes
Quote
hi,

Offseting doesn't help, e.g. when I have a horizontal or [snip]
 

Re:Line

hi Alex,
anyway trying to explain better what you want to ask is convenient for 2
good reasons:
1) you will get more and much useful answers
2) if you know how to explain well your problem then you are very near to
solve it.
Dont mind me too, i just try to give you some advice for the future, ok?
 

Re:Line

hi Ananth,
Quote
Offset the endpoints of the line along the normal's direction. You
will
get two parallel lines.

Lets take the vertical line case ...
with line equation x - 1 = 0;
a = 1 and b = 0, so the normals here would be (1, 0) or (-1, 0).
Lets choose (1, 0)
Thanks a lot for your answer but I am still confused --seems I am too stupid
for that ;)
How to get the line equation ? I mean, if I always use
x - 1 = 0; I always get a = 1 and b = 0, the same for x2 ...
I thought that the 1 here must be in any relation to X1,Y1,X2 or Y2 ?
thanks a lot!
Alex
 

Re:Line

Ok, Alexander ...
Here goes again.
Given 2 pts (X1, Y1) and (X2, Y2), the line equation is
(Y - Y1) = ((Y2 - Y1)/(X2 - X1))(X - X1)
(but X and Y are just that ... X and Y. Dont substiture values for them.)
simplify this to get an equation of the form ax + by + c = 0
Now, any multiples of a and b are your normal.
(X1 + scale * a, Y1 + scale * b) and (X2 + scale * a, Y2 + scale * b) are
the new line coordinates. Adjust scale to get an appropriate thickness for
your polygon.
Regards,
Ananth B.
"Alexander Adam" <XXXX@XXXXX.COM>writes
Quote
hi Ananth,

>Offset the endpoints of the line along the normal's direction. You
will
>get two parallel lines.
>
>Lets take the vertical line [snip]
 

Re:Line

Thanks Ananth,
I tried to get the correct equation and then to get a and b,
but it seems I am too stupid for that kind of stuff...
What am I missing ?
thanks a lot,
Alexander
"Ananth B." <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
Ok, Alexander ...
Here goes again.

Given 2 pts (X1, Y1) and (X2, Y2), the line equation is

(Y - Y1) = ((Y2 - Y1)/(X2 - X1))(X - X1)
(but X and Y are just that ... X and Y. Dont substiture values for them.)

simplify this to get an equation of the form ax + by + c = 0

Now, any multiples of a and b are your normal.

(X1 + scale * a, Y1 + scale * b) and (X2 + scale * a, Y2 + scale * b) are
the new line coordinates. Adjust scale to get an appropriate thickness for
your polygon.

Regards,
Ananth B.

"Alexander Adam" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>hi Ananth,
>
>>Offset the endpoints of the line along the normal's direction. You
>will
>>get two parallel lines.
>>
>>Lets take the vertical line [snip]


 

Re:Line

Hi Alexander,
Ok ... heres some Delphi code
const
DISTANCE_SCALE = 2.0;
procedure ParallelLine(aX1, aY1, aX2, aY2: integer; var aX3, aY3, aX4, aY4:
integer);
var
slope: single;
begin
slope := (aY2 - aY1) / (aX2 - aX1);
aX3 := Round(aX1 + DISTANCE_SCALE * Slope);
aY3 := Round(aY1 + DISTANCE_SCALE * -1);
aX4 := Round(aX2 + DISTANCE_SCALE * Slope);
aY4 := Round(aY2 + DISTANCE_SCALE * -1);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
nx1, ny1, nx2, ny2: integer;
begin
Canvas.MoveTo(10, 10);
Canvas.LineTo(340, 100);
ParallelLine(10, 10, 340, 100, nx1, ny1, nx2, ny2);
Canvas.MoveTo(nx1, ny1);
Canvas.LineTo(nx2, ny2);
end;
Regards,
Ananth B.
"Alexander Adam" <XXXX@XXXXX.COM>writes
Quote
Thanks Ananth,

I tried to get the correct equation and then to get a and b,
but it seems I am too stupid for that kind of [snip]