squaredDistance method

double squaredDistance(
  1. Coordinate3 b
)

Returns the squared distance between two coordinates. Squared distances can be used for comparisons when the actual value is not required.

Performance note: eliminating the square root is an optimization often used in lower-level languages, but the speed difference is not nearly as pronounced in JavaScript (only a few percent.)

@param {goog.math.Coordinate3} b A Coordinate3. @return {number} The squared distance between {@code a} and {@code b}.

Implementation

double squaredDistance(Coordinate3 b)
{
  double dx = this.x - b.x;
  double dy = this.y - b.y;
  double dz = this.z - b.z;
  return dx * dx + dy * dy + dz * dz;
}