[英]So I have a triangle with the point (100, 90) the distance (11) and the angle of the line (45º) Can I find the other point of the line? How?
okay so I am trying to draw a triangle, the triangle can be completely random, on a canvas in JavaScript 好吧所以我试图画一个三角形,三角形可以完全随机,在JavaScript的画布上
so I got the angles and the side for triangle ABC(this is not what I'm calling it in the code) 所以我得到三角形ABC的角度和侧面(这不是我在代码中称之为的)
the sides 双方
AB(11)
AC(12)
BC(13)
the angles which are solved in a function 在函数中求解的角度
BAC(69)
ABC(52)
BCA(59)
And the starting Point of the triangle at (100, 90) 和(100,90)三角形的起点
The question I am having is how do I find the other points to the Triangle I thought the easiest way to draw it would be to draw a line that goes to each point 我遇到的问题是如何找到三角形的其他点我认为绘制它的最简单方法是画一条线到每个点
So I tired the mathematics with this code (I found on another page but ) 所以我用这段代码累了数学(我发现在另一页但是)
function FindTriPoints(){
//Y2 = H(Sin(A)) + Y1
//X2 = Sqrt((H^2)-(Y2^2)) + X1
pointX1 = 100;
pointY1 = 90;
pointY2 = s3 * (Math.sin(angle1*Math.PI/180)) + pointY1;
pointX2 = Math.sqrt((s3 * s3) - (pointY2 * pointY2)) + pointX1;
alert("X2 = " + pointX2 + "\n Y2 = " + pointY2)
}
but X2 ends up becoming NaN because it is a negative value that it is trying to square root. 但是X2最终成为NaN,因为它是一个负值,它试图平方根。
Edit Thanks to Cbroe and Jing3142 for helping me with Y2 编辑感谢Cbroe和Jing3142帮助我Y2
well if you know valid triangle sides lengths (l1,l2,l3) and their angles (a,b,c) ... 好吧,如果你知道有效的三角形边长(l1,l2,l3)和它们的角度(a,b,c)......
// compute directions
a1=0;
a2=180-b;
a3=a2+180-c;
a3=-b-c;
a3=-a;
// convert them from [deg] to [rad]
a1*=Math.pi/180.0;
a2*=Math.pi/180.0;
a3*=Math.pi/180.0;
// compute points
A=(x0,y0); // your start point is known
B=A+l1*dir(a0)=(x0+l1*Math.cos(a0),y0+l1*Math.sin(a0));
B=A+l1*dir( 0)=(x0+l1 ,y0 ); // a0 is always zero
C=A-l3*dir(a3)=(x0-l3*Math.cos(a3),y0-l3*Math.sin(a3)); // C from A point
C=B+l2*dir(a2)=(x0+l1+l2*Math.cos(a2),y0+l2*Math.sin(a2)); // C from B point
[notes] [笔记]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.