三角三角形角度

发布于 2024-10-04 06:52:52 字数 547 浏览 5 评论 0原文

我有一个起点和一个终点。我想计算出角度,我有这个似乎有效的公式

double dx = end.X - start.X;
double dy = end.Y - start.Y;

double degrees = Math.Acos((-Math.Pow(dy, 2) + Math.Pow(dx, 2) + Math.Pow(dx, 2)) / (2 * Math.Pow(dx, 2)));
degrees = degrees * 180 / Math.PI;

然后我想获取角度并延长线的长度。到目前为止我已经有了这个

end.Y = (start.Y + (len * Math.Sin(angle)));
end.X = (start.X + (len * Math.Cos(angle)));

,这并没有给我正确的价值。

白色是原始线,红色是延伸

白色是原始线,红色是延伸

我在做什么

i have a start point and a end point. I want to work out the angle i have this formula that seems to work

double dx = end.X - start.X;
double dy = end.Y - start.Y;

double degrees = Math.Acos((-Math.Pow(dy, 2) + Math.Pow(dx, 2) + Math.Pow(dx, 2)) / (2 * Math.Pow(dx, 2)));
degrees = degrees * 180 / Math.PI;

Then i want to take the angle and extend the line's length. i have this so far

end.Y = (start.Y + (len * Math.Sin(angle)));
end.X = (start.X + (len * Math.Cos(angle)));

now this does not give me the right value.

white is original line and red is the extending

white is original line and red is the extending

what am i doing wro

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

似狗非友 2024-10-11 06:52:52

这就是我在代码中的意思:

double dx = end.X - start.X;
double dy = end.Y - start.Y;

double dlen = Math.Sqrt(dx * dx + dy * dy);

dx = dx / dlen;
dy = dy / dlen;

end.X = start.X + (dx * len);
end.Y = start.Y + (dy * len);

This is what I meant in code:

double dx = end.X - start.X;
double dy = end.Y - start.Y;

double dlen = Math.Sqrt(dx * dx + dy * dy);

dx = dx / dlen;
dy = dy / dlen;

end.X = start.X + (dx * len);
end.Y = start.Y + (dy * len);
狂之美人 2024-10-11 06:52:52

如果您只想继续您的线路,首先您必须找到定义您的线路的函数。

这是一条“简单”的线……它的函数是f(x)=ax+b。找出a和b。

求 a :

a = (start.y - end.y) / (start.x - end.x)
// easy, isn't it ?

求 b :

b = (start.y) - (a * start.x)
// you can check switching "start" by "end"

不涉及角度、余弦或正弦...

再见

If you just want to continue your line, first you'll have to find the function which defines your line.

this is a "simple" line ... it's function is f(x)=ax+b. Find a and b.

To find a :

a = (start.y - end.y) / (start.x - end.x)
// easy, isn't it ?

To find b :

b = (start.y) - (a * start.x)
// you can check switching "start" by "end"

No deal with angles, cosinus or sinus ...

Bye

温柔一刀 2024-10-11 06:52:52

如果你没有斜边(你不需要),你应该使用正切三角函数
就像

  double rads = Math.Atan(dy/dx);

你的学位计算相当复杂,尽管我的方法涉及跟踪象限。请参阅:http://www.mathwizz.com/algebra/help/help29.htm

if you don't have the hypotenuse (which you don't need) you should use a tangent trig function
Like

  double rads = Math.Atan(dy/dx);

Your degree calc is quite convoluted although my way involves keeping track of quadrants. See: http://www.mathwizz.com/algebra/help/help29.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文