码迷,mamicode.com
首页 > 其他好文 > 详细

向量定义笔记

时间:2015-04-02 01:05:02      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TVerctor = record
    X,Y,Z:Pointer;
    VerctorType :(vtInteger,vtDouble);
  public
     class operator Equal(const Left,Right:TVerctor): Boolean;
  end;

  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

{ TVerctor }
const
  verctor_offset_integer=0;
  verctor_offset_double=0.0001;

class operator TVerctor.Equal(const Left, Right: TVerctor): Boolean;
begin
  if (Left.VerctorType<>Right.VerctorType) then Exit(False);
  if (Left.VerctorType=vtInteger) then
    result := (abs(PInteger(Left.X)^-PInteger(Right.X)^)<=verctor_offset_integer)
      and (abs(PInteger(Left.Y)^-PInteger(Right.Y)^)<=verctor_offset_integer)
      and (abs(PInteger(Left.Z)^-PInteger(Right.Z)^)<=verctor_offset_integer)
  else if (Left.VerctorType=vtDouble) then
    Result := (abs(PDouble(Left.X)^-PDouble(Right.X)^)<=verctor_offset_double)
      and (abs(PDouble(Left.Y)^-PDouble(Right.Y)^)<=verctor_offset_double)
      and (abs(PDouble(Left.Z)^-PDouble(Right.Z)^)<=verctor_offset_double)
end;

procedure TForm2.Button1Click(Sender: TObject);
var
  Verctor1,Verctor2:TVerctor;
  x,y,z:Double;
  x1,y1,z1:Double;
begin
  x:=100.1;
  y:=200.2;
  z:=300.0001;
  Verctor1.X:=@x;
  Verctor1.Y:=@y;
  Verctor1.Z:=@z;
  Verctor1.VerctorType:=vtDouble;

  x1:=100.1;
  y1:=200.2;
  z1:=300.0002;
  Verctor2.X:=@x1;
  Verctor2.Y:=@y1;
  Verctor2.Z:=@z1;
  Verctor2.VerctorType:=vtDouble;

  if Verctor1=Verctor2 then ShowMessage(ok);




end;

end.

 

虽然可以实现,但不是我想要的

向量定义笔记

标签:

原文地址:http://www.cnblogs.com/ZhouXiHong/p/4385699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!