如何作曲线图(50分)

  • 主题发起人 主题发起人 ladyboy
  • 开始时间 开始时间
L

ladyboy

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾:
我想在画布上作曲线图,如y=x*x,但无从下手,描点又不够精确。

望各位大虾救我一命!本人不胜感激!
 
先画点,在点点之间画弧线
 
相比直接在画布上画
我觉得使用teechart控件比较好
只要描点足够密
描点怎么会不够精确呢
teechart控件完全可以处理浮点的数据

 
程序员大本营CD中有公式解释控件,结合Teechart作曲线, 效果良好, 我已用在
继电保护装置特性方程绘图.
 
用TeeChart作曲线很不错的。
 
Teechart 正在学,但我以前画过正弦曲线,我不是描点,而是从两点之间
画用直线连起来,感觉还可以,很平滑的。你可以试试看。
 
我做的图(与化学有关)要随提供的数据变化而不同,界面就有输入数据一项,
而且坐标转换也很不方便,精确度有很重要,还望各位大虾详细介绍!!
 
我也听听
 
怎么会描点都不精确,难道能画出0.5点的大小吗?
 
>>怎么会描点都不精确,难道能画出0.5点的大小吗?
错误!!!!!!
如果两个点之间横坐标坐标为a,a+1, 纵坐标为b,b+10,两个点还在一起吗??

 
手工做法:
设置取样点数组,各点间用B样条拟合算法画,则线的精确度取决于取样点的精度。
设置显示比例,使之能够放大缩小。
用已有的VCL控件:
Teechart等
 
Teechart应该可以满足要求
 
只要算法正确,用画布 Canvas.Pixels[x,y] := tcolor;画
很好的.
比如sin
var
x,l: Integer;
y,a: Double;
begin
Image1.Picture.Bitmap := TBitmap.Create;
Image1.Picture.Bitmap.Width := Image1.Width;
Image1.Picture.Bitmap.Height := Image1.Height; {These three lines could
go in Form1.Create instead}
l := Image1.Picture.Bitmap.Width;
for x := 0 to l do
begin
a := (x/l) * 2 * Pi; {Convert position on X to angle between 0 & 2Pi}
y := Sin(a); {Your function would go here}
y := y * (Image1.Picture.Bitmap.Height / 2); {Scale Y so it fits}
y := y * -1; {Invert Y, the screen top is 0 !}
y := y + (Image1.Picture.Bitmap.Height / 2); {Add offset for middle 0}
Image1.Picture.Bitmap.Canvas.Pixels[Trunc(x), Trunc(y)] := clBlack;
end;
end;
A:
I've found the best way is to draw directly onto the canvas. Preferably in a
separate procedure taking a TCanvas and a TRect as parameters. That way you
can pass your window's canvas and client rect as parameters for drawing on
screen and the printer's canvas and a rect comprising of the area where
you wan't it to be positioned to print. Look at the canvasses methods to
get the available drawing routines.
A:
You could use a TCanvas object to draw the function yourself.
A TImage component would be good to use, as it's bitmap contains
a canvas that you can draw on.
eg: (Create a new form, add an Image and a Button. Attach this code
to the button)
var
x,l: Integer;
y,a: Double;
begin
Image1.Picture.Bitmap := TBitmap.Create;
Image1.Picture.Bitmap.Width := Image1.Width;
Image1.Picture.Bitmap.Height := Image1.Height; {These three lines could
go in Form1.Create instead}
l := Image1.Picture.Bitmap.Width;
for x := 0 to l do
begin
a := (x/l) * 2 * Pi; {Convert position on X to angle between 0 & 2Pi}
y := Sin(a); {Your function would go here}
y := y * (Image1.Picture.Bitmap.Height / 2); {Scale Y so it fits}
y := y * -1; {Invert Y, the screen top is 0 !}
y := y + (Image1.Picture.Bitmap.Height / 2); {Add offset for middle 0}
Image1.Picture.Bitmap.Canvas.Pixels[Trunc(x), Trunc(y)] := clBlack;
end;
end;

 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部