TVectorDotProduct (Delphi)

From RAD Studio Code Examples

Description

This example illustrates how to use the DotProduct method to obtain the scalar product of Self and the given vector.

Code

uses
  System.SysUtils,
  System.Types;

var
  aVector1,aVector2: TVector;
  aPoint1, aPoint2:TPointF;
  aProduct: Single;
begin
        aPoint1.Create(4,2);
        aPoint2.Create(1,5);

        aVector1.Create(aPoint1);
        writeln(Format('%2.2f %2.2f',[aVector1.X,aVector1.Y]));
        // The console will output: 4.00 2.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.

        aProduct:=aVector1.DotProduct(aVector2);
        writeln(Format('%2.2f',[aProduct]));
        // The console will output: 14.00, representing the scalar product between aVector1 and aVector2.
end.

Uses