CreateRotationMatrix3D
CreateRotationMatrix3D
Is it a good time now to do a quick retest in XE7?
(In XE4, CreateRotationMatrix3D only worked with positive values for Angle.)
uses
Math,
FMX.Types3D;
procedure TForm1.Button1Click(Sender: TObject);
var
Axis: TVector3D;
Angle: single;
y, s, t: TVector3D;
m1, m2: TMatrix3D;
r: single;
begin
//the finger of the clock at noon
y := TVector3D.Create(0, 1, 0);
//the axis of the finger
Axis := TVector3D.Create(0, 0, 1);
Angle := 1.0;
m1 := CreateRotationMatrix3D(Axis, -Angle);
m2 := CreateRotationMatrix3D(Axis, Angle);
s := Vector3DTransform(y, m1);
t := Vector3DTransform(y, m2);
r := s.Y - t.Y;
//Assert(Abs(r) < Epsilon);
if Abs(r) > Epsilon then
Caption := Format('Hey! %.2f should be 0.00', [r])
else
Caption := 'OK, sin(pi/2 + Angle) = sin(pi/2 - Angle)';
end;
Is it a good time now to do a quick retest in XE7?
(In XE4, CreateRotationMatrix3D only worked with positive values for Angle.)
uses
Math,
FMX.Types3D;
procedure TForm1.Button1Click(Sender: TObject);
var
Axis: TVector3D;
Angle: single;
y, s, t: TVector3D;
m1, m2: TMatrix3D;
r: single;
begin
//the finger of the clock at noon
y := TVector3D.Create(0, 1, 0);
//the axis of the finger
Axis := TVector3D.Create(0, 0, 1);
Angle := 1.0;
m1 := CreateRotationMatrix3D(Axis, -Angle);
m2 := CreateRotationMatrix3D(Axis, Angle);
s := Vector3DTransform(y, m1);
t := Vector3DTransform(y, m2);
r := s.Y - t.Y;
//Assert(Abs(r) < Epsilon);
if Abs(r) > Epsilon then
Caption := Format('Hey! %.2f should be 0.00', [r])
else
Caption := 'OK, sin(pi/2 + Angle) = sin(pi/2 - Angle)';
end;
You could use positive angles only and reverse the direction of the axis as appropiate, but this is a workaround not a solution.
ReplyDeleteI have to change the code slightly in XE7:
ReplyDelete- CreateRotationMatrix3D becomes TMatrix3D.CreateRotation
- Vector3DTransform(y, m) becomes y * m
- Using System.Math.Vectors
Once done, it falls into the OK branch. A quick code inspection looks good too.
David Millington thanks, good to know. In the code, do they test for negative angles now?
ReplyDeleteGustav Schubert No, it simply uses a number of sines and cosines, which should work regardless. There's no code that checks for negative/positive angles or does anything special.
ReplyDelete