具有角度的线方程

Zin*_*inx 27 math geometry

给定起点,线的长度和线的角度(相对于x轴),如何找到线的方程或绘制线?

Art*_*ius 36

你知道起点(x1, x2),终点是长度(x1 + l * cos(ang), y1 + l * sin(ang))在哪里l,ang是角度.

  • 不应该写成:起点你知道```(x1, y1)```... (4认同)

mor*_*lli 18

让我们将起点称为(x1, y1)该行的另一端(x2, y2).

然后,如果给出长度[L]和x轴[a]的角度:

x2 = x1 + (L * cos(a))

y2 = y1 + (L * sin(a))
Run Code Online (Sandbox Code Playgroud)

如果角度来自y轴 - 交换cos和sin.

从您的画线(x1,y1)(x2, y2).

您可能会发现关于线路走向哪个方向的模糊性,您需要注意如何定义角度.


H2O*_*H2O 9

一条线的方程式如下:

m*x + n = y 
Run Code Online (Sandbox Code Playgroud)

m可以通过角度计算; m = tan(angle) 如果你知道一个起点,那么你可以找到n.

tan(angle) * startPoint_X + n = startPoint_Y
Run Code Online (Sandbox Code Playgroud)

所以 n = startPoint_Y - (tan ( angle) * startPoint_X )

如果你想绘制一个线段,你知道长度,起点和角度,将有两个方程.

第一个是m*x + n = y(我们解决了它).

这意味着 m*(endPoint_X) + n = endPoint_Y

第二是找到endPoint.

length^2 = (endPoint_X - startPoint_X)^2 + (endPoint_Y - startPoint_Y)^2
Run Code Online (Sandbox Code Playgroud)

我们只知道两件事:endPoint_x&endPoint_Y如果我们改写等式:

length^2 = (endPoint_X - startPoint_X)^2 + ( m*(endPoint_X) + n - startPoint_Y)^2
Run Code Online (Sandbox Code Playgroud)

现在我们知道除了endPoint_X之外的所有事情.这个等式将为我们提供两个endPoint_X解决方案.然后你可以找到两个不同的ednPoint_Y.

  • 你的第二个方程是错误的,它应该是 startPoint_Y - (tan (angle) * startPoint_X ),但即便如此,答案也比必要的复杂得多。 (2认同)

Van*_*uan 5

实际上有两个不同的问题:一个在标题中,另一个在正文中。

让我们从回答标题中的问题开始:

线方程

一条直线的方程是

y = a*x + b
Run Code Online (Sandbox Code Playgroud)

其中a是直线与 X 轴之间夹角的切线,b是通过 (0, 0) 绘制的直线的高程。

给定角度和点的线方程

您可以轻松计算a(因为您知道角度),但您不知道b. 但是您也知道x0and y0,因此您可以轻松计算b

b = y0 - a*x0 
Run Code Online (Sandbox Code Playgroud)

现在,等式如下所示:

y = tan(fi)*x + y0 - tan(fi)*x0 = tan(fi)*(x - x0) + y0
Run Code Online (Sandbox Code Playgroud)

画一段给定的点、角度、长度

我们想从起点绘制一条线段,使其长度为 L,与 x 轴的角度为 fi。

这是一个完全不同的问题。

你应该想象一个直角三角形,它的锐角位于 (x0, y0)。

你知道斜角 (L) 和角度 (fi)。

根据定义,

a = L*cos(fi) (adjacent, x)
b = L*sin(fi) (opposite, y)
Run Code Online (Sandbox Code Playgroud)

您只需要添加 x0 和 y0:

x1 = x0 + L*cos(fi)
y1 = y0 + L*sin(fi)
Run Code Online (Sandbox Code Playgroud)