已知平面上n个点的坐标,如何做经过这n个点的闭合曲线?(200分)

  • 主题发起人 主题发起人 tanxi
  • 开始时间 开始时间
T

tanxi

Unregistered / Unconfirmed
GUEST, unregistred user!
正文如题;
有没有现成的函数可以使用;
 
有没有现成的函数不知道,但自己写一个也不难。
首先将点按照x,y进行排序,按一个方向将他们加入点集。再用Api画折线的函数画就行了
 
可能我没有讲清楚,我要的不是封闭的折线,而是光滑的封闭曲线。
 
要做样条曲线,简单点你可以用Bezier画,但曲线不是很逼近,我给你个网址,下载例子看看。

http://www.programmersheaven.com/zone2/cat262/16261.htm
 
你看看MSDN, 有個API可能是你要的:
PolylineTo
The PolylineTo function draws one or more straight lines.

BOOL PolylineTo(
HDC hdc, // handle to device context
CONST POINT *lppt, // array of points
DWORD cCount // number of points in array
);
 
呵呵,自己画吧,没有现成的

给你个我的例子,25*25个点,除边界外每个点与上下左右4个点连

var
y:array[0..624] of integer;
x:array[0..624] of integer;
i,j,l,m:integer;
buf:byte;
f:tfilestream;
s:string;
begin
form1.DoubleBuffered :=true;
f:= TfileStream.Create('C:/wg', fmOpenRead);
image2.Canvas.Pen.Color :=clyellow;
for i:=0 to 624 do
begin
f.Seek(4*i, soFromBeginning);
f.Read(buf,1);
s :=IntToHex(buf,2);
f.Read(buf,1); // 再读出1字节
s:=s+IntToHex(buf,2);
y:=trunc((strtoint('$'+s ))/d);

f.Read(buf,1);
s :=IntToHex(buf,2);
f.Read(buf,1); // 再读出1字节
s :=s+IntToHex(buf,2);
x:=trunc((strtoint('$'+s ))/c);
end;
f.Free ;
image2.Canvas.MoveTo (x[0],y[0]);
for j:=1 to 624 do
begin
if (j mod 25=0) then
begin
image2.Canvas.MoveTo (x[j],y[j]);
end
else
begin
image2.Canvas.LineTo (x[j],y[j]);
end;
end;
for m:=0 to 24 do
begin
image2.Canvas.MoveTo (x[m],y[m]);
for l:=1 to 24 do
begin
image2.Canvas.LineTo (x[l*25+m],y[l*25+m]);
end;
end;
end;
 
用Bezier画是光滑曲线但不经过这n个点,PolylineTo经过这n个点但不是光滑曲线,
两者不能兼得,有些遗憾,不过还是散分。
 
用Bezier画是光滑曲线但不经过这n个点,PolylineTo经过这n个点但不是光滑曲线,
两者不能兼得,有些遗憾,不过还是散分。
 
后退
顶部