TVectorReflect (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example illustrates how to use the Reflect method to obtain the reflection of the given vector against a normalized wall vector.

Code

uses
  System.SysUtils,
  System.Types;

var
  aVector1,aVector2,aVector3: TVector;
  aPoint1, aPoint2: TPointF;

begin
   aPoint1.Create(2,3);
   aPoint2.Create(1,5);

   aVector1.Create(aPoint1);
   writeln(Format('%2.2f %2.2f',[aVector1.X,aVector1.Y]));
   // The console will output: 2.00 3.00, representing the coordinates for aVector1.

   aVector2.Create(aPoint2);
   writeln(Format('%2.2f %2.2f',[aVector2.X,aVector2.Y]));
   // The console will output:  1.00 5.00, representing the coordinates for aVector2.

   aVector3:=aVector1.Reflect(aVector2);
   writeln(Format('%2.2f %2.2f',[aVector3.X,aVector3.Y]));
   // The console will output: -32.00 -167.00, representing the coordinates for aVector3 as a reflected vector.
end.

Uses