如何找出 {X=569,Y=71} {X=735,Y=91} 之间的直线上的所有点

发布于 2024-12-20 14:07:33 字数 1459 浏览 4 评论 0 原文

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

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

发布评论

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

评论(1

优雅的叶子 2024-12-27 14:07:33

我怀疑您正在使用整数除法来计算斜率。

Gabe 在 Bresenham 线算法的评论中给出的链接将说明快速高效的纯整数解决方案。

如果您可以使用浮点,请以浮点类型计算斜率。如果线很陡,您可能需要增加 y 而不是 x。无论哪种方式,使用斜率和您正在步进的另一个坐标将一个坐标计算为浮点数。然后(正确地)四舍五入到最接近的整数。

I suspect you're computing the slope using an integer divide.

The link Gabe gave in the comments to the Bresenham line algorithm will illustrate a purely integer solution that's fast and efficient.

If you're OK using floating point, compute the slope as a floating point type. If the line is steep, you probably want to increment in y instead of x. Either way, compute one coordinate as a floating point number using the slope and the other coordinate that you're stepping. Then round (correctly) to the nearest integer.

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