unit uvektor;
interface
uses types,math,sysutils;
type
tvektor3=packed
record
x,y,z:extended;
//addition
class operator add(a,b:tvektor3):tvektor3;
class operator add(a:tvektor3;b:extended):tvektor3;
class operator add(b:extended;a:tvektor3):tvektor3;
//subtraktion
class operator Subtract(a,b:tvektor3):tvektor3;
class operator Subtract(a:tvektor3;b:extended):tvektor3;
class operator Subtract(b:extended;a:tvektor3):tvektor3;
//Multiplikation
class operator Multiply(a,b:tvektor3):tvektor3;
class operator Multiply(a:tvektor3;b:extended):tvektor3;
class operator Multiply(b:extended;a:tvektor3):tvektor3;
//Division
class operator Divide(a,b:tvektor3):tvektor3;
class operator Divide(a:tvektor3;b:extended):tvektor3;
class operator Divide(b:extended;a:tvektor3):tvektor3;
//negatives Vorzeichen
class operator Negative(a:tvektor3):tvektor3;
// größer als
class operator GreaterThan(a,b:tvektor3):boolean;
//kleiner als
class operator LessThan(a,b:tvektor3):boolean;
end;
pvektor3=^tvektor3;
function createvektor(x,y,z:extended):tvektor3;
function skalarbetrag(a:tvektor3):extended;
function entfernung(a,b:tvektor3):extended;
//ab
function vektortostr(a:tvektor3):
string;
implementation
//addition
class operator tvektor3.add(a,b:tvektor3):tvektor3;
begin
result.x:=a.x+b.x;
result.y:=a.y+b.y;
result.z:=a.z+b.z;
end;
class operator tvektor3.add(a:tvektor3;b:extended):tvektor3;
begin
result.x:=a.x+b;
result.y:=a.y+b;
result.z:=a.z+b;
end;
class operator tvektor3.add(b:extended;a:tvektor3):tvektor3;
begin
result.x:=a.x+b;
result.y:=a.y+b;
result.z:=a.z+b;
end;
//subtraktion
class operator tvektor3.subtract(a,b:tvektor3):tvektor3;
begin
result.x:= a.x-b.x;
result.y:= a.y-b.y;
result.z:= a.z-b.z;
end;
class operator tvektor3.subtract(a:tvektor3;b:extended):tvektor3;
begin
result.x:= a.x-b;
result.y:= a.y-b;
result.z:= a.z-b;
end;
class operator tvektor3.subtract(b:extended;a:tvektor3):tvektor3;
begin
result.x:= b-a.x;
result.y:= b-a.y;
result.z:= b-a.z;
end;
// multiplikation
class operator tvektor3.Multiply(a,b:tvektor3):tvektor3;
begin
result.x:=a.x*b.x;
result.y:=a.y*b.y;
result.z:=a.z*b.z;
end;
class operator tvektor3.Multiply(a:tvektor3;b:extended):tvektor3;
begin
result.x:=a.x*b;
result.y:=a.y*b;
result.z:=a.z*b;
end;
class operator tvektor3.Multiply(b:extended;a:tvektor3):tvektor3;
begin
result.x:=a.x*b;
result.y:=a.y*b;
result.z:=a.z*b;
end;
//Division
class operator tvektor3.Divide(a,b:tvektor3):tvektor3;
begin
result.x:=a.x/b.x;
result.y:=a.y/b.y;
result.z:=a.z/b.z;
end;
class operator tvektor3.Divide(a:tvektor3;b:extended):tvektor3;
begin
result.x:=a.x/b;
result.y:=a.y/b;
result.z:=a.z/b;
end;
class operator tvektor3.Divide(b:extended;a:tvektor3):tvektor3;
begin
result.x:=b/a.x;
result.y:=b/a.y;
result.z:=b/a.z;
end;
//Negatives Vorzeichen
class operator tvektor3.Negative(a:tvektor3):tvektor3;
begin
a.x:=-a.x;
a.y:=-a.y;
a.z:=-a.z;
end;
// größer als
class operator tvektor3.greaterthan(a,b:tvektor3):boolean;
begin
result:=false;
if (a.x>b.x)
or(a.y>b.y)
or(a.z>b.z)
then
result:=true;
end;
//kleiner als
class operator tvektor3.LessThan(a,b:tvektor3):boolean;
begin
result:=false;
if (a.x<b.x)
or(a.y<b.y)
or(a.z<b.z)
then
result:=true;
end;
//standart funktionen
function entfernung(a,b:tvektor3): extended;
begin
result:=skalarbetrag(a-b);
end;
function createvektor(x,y,z:extended):tvektor3;
begin
result.X:=x;
result.Y:=y;
result.z:=Z;
end;
function skalarbetrag(a:tvektor3):extended;
begin
result:=sqrt(power(a.x,2)+power(a.y,2)+power(a.z,2));
end;
function vektortostr(a:tvektor3):
string;
begin
result:=floattostr(a.x)+'
/'+floattostr(a.y)+'
/'+floattostr(a.z)
end;
end.