用于计算几何的最佳直线方程
我正在寻找用 Ruby 编写一个小型 comp-geom 库。
我即将编写线代码,并且想知道应该使用哪个线方程:
- ax + by + c = 0
- r + tv (其中 r 和 v 是向量)
谢谢。
I'm looking to write a little comp-geom library, in Ruby.
I'm about to write the code for lines, and was wondering which line equation I should use:
- ax + by + c = 0
- r + tv (where r and v are vectors)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不需要使用经典方程,我建议使用四个坐标的数组:xStart、yStart、xEnd 和 yEnd。
如果您需要使线位置动态化,您可以使用两个参数的数组:alpha 和 radius。前者表示相对于水平轴的径向旋转,后者表示线的长度。
另一种选择是 (X;Y) 形式的向量。
C 语言示例:
“endpoints”格式与现代画线算法完全兼容,例如 Xiaolin Wu 的直线算法和Bresenham直线算法,但它代表特定的屏幕坐标, “径向”和“矢量”格式则不然。
If using the classical equations is not a requirement, I'd suggest an array of four co-ordinates: xStart, yStart, xEnd and yEnd.
In case you need to make the line position dynamic, you could use an array of two parameters: alpha and radius. The former represents radial rotation relative to the horizontal axis and the latter is the length of line.
Yet another option would be vectors in the form of (X;Y).
Samples in C:
The "endpoints" format is fully compatible with modern line-drawing algorithms, such as Xiaolin Wu's line algorithm and Bresenham's line algorithm but it represents specific screen co-ordinates which is not the case with "radial" and "vector" format.