SC2Mapster.com Wiki

SC2 API / Functions / AngleBetweenPoints

AngleBetweenPoints

fixed AngleBetweenPoints(fixed a, fixed b);

Angle (in degrees) between a and b

Parameters

fixed a

First point

fixed b

Second point

Return value

fixed - The angle in degrees between a and b. The value is between -180° (excluded) and 180°

Examples

Example #1: Sample Usage
AngleBetweenPoints(Point(0, 0), Point(1, 1)) // 45°
AngleBetweenPoints(Point(1, 1), Point(0, 0)) // -135°
AngleBetweenPoints(Point(0, 0), Point(0, 0)) // -90°
AngleBetweenPoints(Point(1, 0), Point(0, 1)) // 135°
AngleBetweenPoints(Point(0, 0), Point(0, 1)) // 90°
AngleBetweenPoints(Point(0, 0), Point(1, 0)) // 0°
AngleBetweenPoints(Point(0, 0), Point(-1, 0); // 180°
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: Point Along Line
point PointAlongLine (point from, point toward, fixed distance) {
    return PointWithOffsetPolar(from, distance, 
                                 AngleBetweenPoints(toward, from));
}

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 12, 2010

Author