我正在编写一个程序,可以在十进位和极坐标系中绘制蛇本克斯三角形。我认为使用Polygon()
将是完美的,但由于某种原因,它没有画出三角形,而是画出了一条直线。我不明白为什么,我也找不到答案。
下面是代码:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TGraphForm = class(TForm)
img1: TImage;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
GraphForm: TGraphForm;
implementation
uses
Unit1;
{$R *.dfm}
procedure TGraphForm.FormActivate(Sender: TObject);
var
Ax, Ay, Bx, By, Cx, Cy: integer;
x0, y0 :integer;
begin
//взятие параметров Defining Points of Triangle
Ax := StrToInt(MainForm.EditAx.Text);
Ay := StrToInt(MainForm.EditAy.Text);
Bx := StrToInt(MainForm.EditBx.Text);
By := StrToInt(MainForm.EditBx.Text);
Cx := StrToInt(MainForm.EditCx.Text);
Cy := StrToInt(MainForm.EditCx.Text);
//0 функции Center of system (0;0)
x0 := img1.Width div 2;
y0 := img1.Height div 2;
//Оси Drawing Axis
with img1.Canvas do
begin
MoveTo(x0,0);
LineTo(x0, ClientHeight);
MoveTo(0, y0);
LineTo(ClientWidth, y0);
end;
//график
//главный треугольник
with img1.Canvas do
begin
Polygon ([Point(-Ax+x0,-Ay+y0), Point(-Bx+x0,-By+y0), Point(-Cx+x0,-Cy+y0)]);
end;
end;
end.
2条答案
按热度按时间deikduxw1#
所以,在Remy Lebeau(伟人)的帮助下,我修复了这个问题。实际上,我不知道是怎么做到的,但是现在它工作了。下面是修改后的代码: