SRL Archive - Help and Support

I need an algorithm for breaking down lines.


R0b0t1

2007-11-03 22:44:22

So, I understand you've all used paint before, right? Notice how it breaks the line up into smaller segments to make it seem like it is at an angle? I need an algorithm that does that.


I don't want to experiment with it. I'm lazy.

R0b0t1

2007-11-04 12:18:14

Bump. I really need help.

Miitchyy

2007-11-04 17:07:43

Possibly something like angle over length?

R0b0t1

2007-11-04 19:54:09

No… Something that can connect two points with a line, but the points aren't even. I need to split the line up into smaller segments to make it seem like its one line. I then need to get those points into an array…

jhildy

2007-11-04 21:59:29

How could you get the angle? if you can get me that ill try.

Boreas

2007-11-04 22:21:59

function PointsOfLine(x1,y1,x2,y2:integer): tpointarray;
var slope,yint:extended;
i:integer;
begin
slope:=(y2-y1)/(x2-x1);
writeln(floattostr(slope));
yint:=(y1-(x1*(slope)));
if abs(slope) >1.0 then
begin
setarraylength(result,round(abs(y2-y1))+1);
for i:=0 to getarraylength(result)-1 do
begin
result[i].y:=y1-i;
result[i].x:=round((result[i].y-yint)/slope);
end;
exit;
end
setarraylength(result,round(abs(x2-x1))+1);
for i:=0 to getarraylength(result)-1 do
begin
result[i].x:=x1+i;
result[i].y:=round((result[i].x*slope)+yint);
end;
end;

close but needs tweaking

SKy Scripter

2007-11-04 22:57:23

From: Boreas
function PointsOfLine(x1,y1,x2,y2:integer): tpointarray;
var slope,yint:extended;
i:integer;
begin
slope:=(y2-y1)/(x2-x1);
writeln(floattostr(slope));
yint:=(y1-(x1*(slope)));
if abs(slope) >1.0 then
begin
setarraylength(result,round(abs(y2-y1))+1);
for i:=0 to getarraylength(result)-1 do
begin
result[i].y:=y1-i;
result[i].x:=round((result[i].y-yint)/slope);
end;
exit;
end
setarraylength(result,round(abs(x2-x1))+1);
for i:=0 to getarraylength(result)-1 do
begin
result[i].x:=x1+i;
result[i].y:=round((result[i].x*slope)+yint);
end;
end;

close but needs tweaking


Or you could do my way :p


function DrawLine(Sx, Sy, Ex, Ey, Step : Integer) : TPointArray;
var t, ta : Extended;
x, y, i : Integer;
begin
t := (Step / hypot(ex - sx, ey - sy));
SetLength(Result, Trunc((1 / t)+1));
repeat
ta := ta + t;
Result[i].x := round((ex * ta) + (sx * (1-ta)));
Result[i].y := round((ey * ta) + (sy * (1-ta)));
inc(i);
until ta >= 1;
SetLength(Result, i);
end;

Boreas

2007-11-05 00:56:30

Not if you want it to look like a line made by paint's line tool :p

SKy Scripter

2007-11-05 01:08:42

From: Boreas
Not if you want it to look like a line made by paint's line tool :p


yours drew the same look as mine XD

lol :p

Boreas

2007-11-05 01:23:01

Bah nvm

goider

2007-11-05 17:32:43

y=mx+B i know its wrong buti feel like it.

R0b0t1

2007-11-06 21:20:30

Nice. Thanks guys.