MCPcopy
hub / github.com/chartjs/Chart.js / getAngleFromPoint

Function getAngleFromPoint

src/helpers/helpers.math.ts:124–142  ·  view source on GitHub ↗
(
  centrePoint: Point,
  anglePoint: Point
)

Source from the content-addressed store, hash-verified

122
123// Gets the angle from vertical upright to the point about a centre.
124export function getAngleFromPoint(
125 centrePoint: Point,
126 anglePoint: Point
127) {
128 const distanceFromXCenter = anglePoint.x - centrePoint.x;
129 const distanceFromYCenter = anglePoint.y - centrePoint.y;
130 const radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
131
132 let angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
133
134 if (angle < (-0.5 * PI)) {
135 angle += TAU; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
136 }
137
138 return {
139 angle,
140 distance: radialDistanceFromCenter
141 };
142}
143
144export function distanceBetweenPoints(pt1: Point, pt2: Point) {
145 return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));

Callers 2

evaluationFuncFunction · 0.85
inRangeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected