use*_*957 1 javascript line points calculation
我有2个点A1(x1,y1)和A2(x2,y2)的坐标以及距离d。我需要在由A1和A2定义的线性图上找到点A3的坐标,该坐标是到点A2的距离d。如何使用JavaScript做到这一点?类似于https://softwareengineering.stackexchange.com/questions/179389/find-the-new-coordinates-using-a-starting-point-a-distance-and-an-angle
已知角度的情况
小智 5
var A1 = {
x : 2,
y : 2
};
var A2 = {
x : 4,
y : 4
};
// Distance
var d= 2;
// Find Slope of the line
var slope = (A2.y-A1.y)/(A2.x-A1.x);
// Find angle of line
var theta = Math.atan(slope);
// the coordinates of the A3 Point
var A3x= A2.x + d * Math.cos(theta);
var A3y= A2.y + d * Math.sin(theta);
console.log(A3x);
console.log(A3y);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
272 次 |
| 最近记录: |