lineDistance.glsl 554 B

1234567891011121314
  1. /**
  2. * Computes distance from an point in 2D to a line in 2D.
  3. *
  4. * @name czm_lineDistance
  5. * @glslFunction
  6. *
  7. * param {vec2} point1 A point along the line.
  8. * param {vec2} point2 A point along the line.
  9. * param {vec2} point A point that may or may not be on the line.
  10. * returns {float} The distance from the point to the line.
  11. */
  12. float czm_lineDistance(vec2 point1, vec2 point2, vec2 point) {
  13. return abs((point2.y - point1.y) * point.x - (point2.x - point1.x) * point.y + point2.x * point1.y - point2.y * point1.x) / distance(point2, point1);
  14. }