delphi 如何吸引男人

5us2dqdw  于 2022-11-04  发布在  其他
关注(0)|答案(2)|浏览(104)

我正在编写一个程序,可以在十进位和极坐标系中绘制蛇本克斯三角形。我认为使用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.
deikduxw

deikduxw1#

所以,在Remy Lebeau(伟人)的帮助下,我修复了这个问题。实际上,我不知道是怎么做到的,但是现在它工作了。下面是修改后的代码:

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, System.Types;
type
  TGraphForm = class(TForm)
    img: 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
  // переменные Variables
  Ax, Ay, Bx, By, Cx, Cy: integer;
  x0, y0 :integer;
  scale :integer;
begin
     // координаты вершин  Points of triangle
  Ax := StrToInt(MainForm.EditAx.Text)*-1;
  Ay := StrToInt(MainForm.EditAy.Text)*-1;
  Bx := StrToInt(MainForm.EditBx.Text)*-1;
  By := StrToInt(MainForm.EditBy.Text)*-1;
  Cx := StrToInt(MainForm.EditCx.Text)*-1;
  Cy := StrToInt(MainForm.EditCy.Text)*-1;
   // точка пересечения осей Where is the zero
  x0 := img.Width div 2;
  y0 := img.Height div 2;
  // множитель масштабирования scale multiplier
  scale :=-40;

  with img.Canvas do
    begin
    //рисование осей    drawing Axises
      MoveTo(x0, 0);
      LineTo(x0, img.Height);
      MoveTo(0, y0);
      LineTo(img.Width, y0);
      //Making poligon (triangle)
      Brush.Color := clBlack;
      Polygon( [Point(Ax*scale+x0, Ay*-scale+y0), Point(Bx*scale+x0, By*-scale+y0), Point(Cx*scale+x0, Cy*-scale+y0)] );
    end;
end;
end.

相关问题