SC2Mapster.com Wiki

SC2 API / Functions / DistanceBetweenPoints

DistanceBetweenPoints

fixed DistanceBetweenPoints(fixed a, fixed b);

Distance between a and b

Parameters

fixed a

First point

fixed b

Second point

Return value

fixed - The distance between a and b.

Examples

Example #1: Sample Usage
DistanceBetweenPoints(Point(0, 0), Point(1, 1))
// Sqrt(2) ~= 1.41421356
DistanceBetweenPoints(Point(0, 0), Point(0, 10))
// 10
Example #2: PointXY
fixed PointX(point p) {
  point ref = Point(0, 0);

  return cos(DegToRad(AngleBetweenPoints(ref, p)))
    * DistanceBetweenPoints(ref, p);
}

fixed PointY(point p) {
  point ref = Point(0, 0);

  return sin(DegToRad(AngleBetweenPoints(ref, p)))
    * DistanceBetweenPoints(ref, p);
}
// Note: It requires cos and sin.
// http://www.sc2mapster.com/assets/basic-mathematic-functions/
Example #3: IsPlayerWatching
// Tell if the player camera can see the unit
bool IsPlayerWatching(int player, unit u) {
  point cameraPos = CameraGetTarget(player);
  point unitPos = UnitGetPosition(u);

  return DistanceBetweenPoints(cameraPos, unitPos) < 20;
}
  • distance.jpg

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Mar 12, 2010
Last updated
Mar 24, 2010

Author