简单的数学算法:直线的中心点

发布于 2024-12-15 01:55:01 字数 304 浏览 4 评论 0原文

我有一个如下的算法来查找线的中心(中点)。

public DoublePoint getMidPoint() {
    return new DoublePoint((origin.x + endPoint.x) / 2, (origin.y + endPoint.y) / 2);
}

它似乎适用于任何价值观。但我似乎记得一个更复杂的算法,涉及两个圆,其半径等于线的长度,其中心点是线的两端。从这些圆的交点绘制的线将与您正在测试的线段相交,给出该线的中点。我确信该算法 100% 有效。不确定我的更简单的算法似乎太简单了。

I have an algorithm as follows for finding the center of a line (midpoint).

public DoublePoint getMidPoint() {
    return new DoublePoint((origin.x + endPoint.x) / 2, (origin.y + endPoint.y) / 2);
}

It seems to work for any values. But I seem to remember a much more complex algorithm, involving two circles whose radius equals the length of the line and whose center points are the ends of the line. A line drawn from the intersection of those circles would intersect the line segment you are testing, giving the line's midpoint. I know for sure that algorithm works 100% of the time. Not sure about my simpler algorithm which seems too simple.

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

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

发布评论

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

评论(5

往日 2024-12-22 01:55:01

您所记住的是仅使用圆规和直尺构造线段垂直平分线的几何方法。例如,考虑一下:

在此处输入图像描述

这对于古希腊人来说很好,但还有其他方法(例如你已经编码的一个)对于计算机来说效果更好。

What you are remembering is a geometric method of constructing the perpendicular bisector of a line segment using only a compass and straightedge. Consider, for instance:

enter image description here

This was fine for the ancient Greeks, but there are other methods (such as the one you have coded) which work better for computers.

狂之美人 2024-12-22 01:55:01

你的简单算法是完全正确的。圆的方法是用圆规找到中点。

Your simple algoritm is full correct. Method with circles is a finding the midpoint with pair of compasses.

烟─花易冷 2024-12-22 01:55:01

你依稀记得的算法是使用直尺和圆规来获得中点。绘制以线段两端为中心的两个半径相等的圆,使它们相交——线段的长度就可以了。使用直尺连接圆相交的点。这条线与原始线段的交点就是中点。精美动画 http://www.mathopenref.com/constbisectline.html

The algorithm you vaguely remember is to use a straightedge and a compass to get the midpoint. Draw take two equal radius circles centered on the two ends of the line segment in such way that they intersect -- the length of the line segment will do. Use the straightedge to connect the points where the circles intersect. Where this line intersects the original line segment is the midpoint. Fancy animation at http://www.mathopenref.com/constbisectline.html

难得心□动 2024-12-22 01:55:01

您拥有的算法和代码是执行此操作的最简单且最好的方法。

The algorithm and code you have is the simplest and best way to do this.

拥抱没勇气 2024-12-22 01:55:01

您的算法是将线平移到原点的简化,找到该线表示的向量,将其减半,然后将其平移回原始线。简化是有效的,算法是正确的。

Your algorithm is a simplification of translating the line to the origin, finding the vector represented by that line, halving it, then translating it back to the original line. The simplification is valid, and the algorithm is correct.

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