DistanceΒΆ

The various overloads of squared_distance() calculate the squared distance between a query point and several different primitives:

  • another point,

  • a BoundingBox,

  • a Segment,

  • a Triangle.

Diagram showing 3D point-triangle orientation test.
#include "axom/primal/operators/squared_distance.hpp"
  // The point from which we'll query
  PointType q = PointType::make_point(0.75, 1.2, 0.4);

  // Find distance to:
  PointType p {0.2, 1.4, 1.1};
  SegmentType seg(PointType {1.1, 0.0, 0.2}, PointType {1.1, 0.5, 0.2});
  TriangleType tri(PointType {0.2, -0.3, 0.4},
                   PointType {0.25, -0.1, 0.3},
                   PointType {0.3, -0.3, 0.35});
  BoundingBoxType bbox(PointType {-0.3, -0.2, 0.7}, PointType {0.4, 0.3, 0.9});

  double dp = squared_distance(q, p);
  double dseg = squared_distance(q, seg);
  double dtri = squared_distance(q, tri);
  double dbox = squared_distance(q, bbox);

The example shows the squared distance between the query point, shown in black in the figure, and four geometric primitives. For clarity, the diagram also shows the projection of the query point and its closest points to the XY plane.