![](/img/trans.png)
[英]I need to draw a triangle from a line segment - How do I find the center point?
[英]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?
好吧所以我试图画一个三角形,三角形可以完全随机,在JavaScript的画布上
所以我得到三角形ABC的角度和侧面(这不是我在代码中称之为的)
双方
AB(11)
AC(12)
BC(13)
在函数中求解的角度
BAC(69)
ABC(52)
BCA(59)
和(100,90)三角形的起点
我遇到的问题是如何找到三角形的其他点我认为绘制它的最简单方法是画一条线到每个点
所以我用这段代码累了数学(我发现在另一页但是)
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)
}
但是X2最终成为NaN,因为它是一个负值,它试图平方根。
编辑感谢Cbroe和Jing3142帮助我Y2
好吧,如果你知道有效的三角形边长(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
[笔记]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.