Vector Dot Product#

Synopsis#

Dot product of Vectors

Results#

Output:

u :[-1, 1, -1]
v :[1, 2, 3]
DotProduct( u, v ) = -2
u - DotProduct( u, v ) * v = [1, 5, 5]

Code#

C++#

#include "itkVector.h"

int
main()
{
  constexpr unsigned int Dimension = 3;
  using CoordType = double;

  using VectorType = itk::Vector<CoordType, Dimension>;

  VectorType u;
  u[0] = -1.;
  u[1] = 1.;
  u[2] = -1.;

  VectorType v;
  v[0] = 1.;
  v[1] = 2.;
  v[2] = 3.;

  std::cout << "u :" << u << std::endl;
  std::cout << "v :" << v << std::endl;
  std::cout << "DotProduct( u, v ) = " << u * v << std::endl;
  std::cout << "u - ( u * v ) * v = " << u - (u * v) * v << std::endl;

  return EXIT_SUCCESS;
}

Python#

#!/usr/bin/env python

import itk
from numpy.core import double

Dimension = 3
CoordType = itk.D

VectorType = itk.Vector[CoordType, Dimension]

u = VectorType()
u[0] = -1.0
u[1] = 1.0
u[2] = -1.0

v = VectorType()
v[0] = 1.0
v[1] = 2.0
v[2] = 3.0

print("u: " + str(u))
print("v: " + str(v))
print("DotProduct( u, v ) = " + str(u * v))
print("DotProduct( u, v ) = " + str(u - double(u * v) * v))

Classes demonstrated#

template<typename T, unsigned int NVectorDimension = 3>
class Vector : public itk::FixedArray<T, NVectorDimension>

A templated class holding a n-Dimensional vector.

Vector is a templated class that holds a single vector (i.e., an array of values). Vector can be used as the data type held at each pixel in an Image or at each vertex of an Mesh. The template parameter T can be any data type that behaves like a primitive (or atomic) data type (int, short, float, complex). The NVectorDimension defines the number of components in the vector array.

Vector is not a dynamically extendible array like std::vector. It is intended to be used like a mathematical vector.

If you wish a simpler pixel types, you can use Scalar, which represents a single data value at a pixel. There is also the more complex type ScalarVector, which supports (for a given pixel) a single scalar value plus an array of vector values. (The scalar and vectors can be of different data type.)

See

Image

See

Mesh

See

Point

See

CovariantVector

See

Matrix

ITK Sphinx Examples:

See itk::Vector for additional documentation.