TVector3DDotProduct (Object Pascal)

From Appmethod Code Examples
Jump to: navigation, search

Description

This example illustrates how to use the DotProduct method to obtain the scalar product between two 3D vectors.

Code

uses
  System.SysUtils,
  System.Types;

var
  aVector1, aVector2: TVector3D;
  aValue: Single;

begin
    aVector1.Create(1, 2, 4);
    writeln(Format('%2.2f %2.2f %2.2f', [aVector1.X, aVector1.Y, aVector1.Z]));
    // The console will output: 1.00 2.00 4.00, representing the coordinates for aVector1.

    aVector2.Create(2, 3, 4);
    writeln(Format('%2.2f %2.2f %2.2f', [aVector2.X, aVector2.Y, aVector2.Z]));
    // The console will output: 2.00 3.00 4.00, representing the coordinates for aVector2.

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

Uses