10 examples of 'matlab angle between two points' in JavaScript

Every line of 'matlab angle between two points' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
54export function calculateAngleBetweenPoints(A: GeometricalPoint, B: GeometricalPoint, C: GeometricalPoint): number {
55 // Calculate length of each line in the triangle formed by A, B, C.
56 const AB = calculateDistanceBetweenTwoPoints(A, B);
57 const BC = calculateDistanceBetweenTwoPoints(B, C);
58 const AC = calculateDistanceBetweenTwoPoints(A, C);
59
60 // Arccosine is the inverse function of a cosine, i.e. given a cosine,
61 // it calculates the corresponding angle.
62 return Math.acos((BC * BC + AB * AB - AC * AC) / (2 * BC * AB));
63};
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

241function angleBetween(v1, v2) {
242 var adotb = (v1[0]*v2[0] + v1[1]*v2[1])/Math.sqrt((v1[0]*v1[0] + v1[1]*v1[1])*(v2[0]*v2[0] + v2[1]*v2[1]));
243 var cross = v1[0]*v2[1]-v1[1]*v2[0];
244 return (cross!=0?cross/Math.abs(cross):1)*Math.acos(adotb);
245}
46export function angleBetween(u: number[], v: number[]): number {
47 var ux = u[0],
48 uy = u[1],
49 vx = v[0],
50 vy = v[1];
51 var num = ux * vx + uy * vy;
52 var den = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
53 return Math.acos(num / den);
54}
329function getAngle(a, b) {
330 const point = { x: b.x - a.x, y: b.y - a.y };
331 return Math.atan2(point.y, point.x);
332}
369function angleBetween(v0, v1) {
370 var p = v0.x*v1.x + v0.y*v1.y;
371 var n = Math.sqrt((Math.pow(v0.x, 2)+Math.pow(v0.y, 2)) * (Math.pow(v1.x, 2)+Math.pow(v1.y, 2)));
372 var sign = v0.x*v1.y - v0.y*v1.x < 0 ? -1 : 1;
373 var angle = sign*Math.acos(p/n);
374
375 //var angle = Math.atan2(v0.y, v0.x) - Math.atan2(v1.y, v1.x);
376
377 return angle;
378}
260function angle(a, b) {
261 return Math.atan2(b[1] - a[1], b[0] - a[0]);
262}
45function getAngle(x1, y1, x2, y2) {
46 return Math.atan2(y2-y1, x2-x1);
47}
105angleWithSep(x, y) {
106 return Math.atan2(
107 this.x * y - this.y * x,
108 this.x * x + this.y * y);
109}
105function findAngle(A, B, C) {
106 //A first point; C second point; B center point
107 var pi = 3.14159265;
108 var AB = Math.sqrt(Math.pow(B[0] - A[0], 2) + Math.pow(B[1] - A[1], 2));
109 var BC = Math.sqrt(Math.pow(B[0] - C[0], 2) + Math.pow(B[1] - C[1], 2));
110 var AC = Math.sqrt(Math.pow(C[0] - A[0], 2) + Math.pow(C[1] - A[1], 2));
111 return Math.acos((BC * BC + AB * AB - AC * AC) / (2 * BC * AB)) * (180 / pi);
112}
180solveAngle(a, b = this) {
181 return Math.atan2(a.y - b.y, a.x - b.x);
182}

Related snippets