两点之间的直线方程

发布于 2024-09-05 19:07:09 字数 584 浏览 5 评论 0原文

我需要画出连接两点的线。

我正在用 Java 做这件事。我收到两个点作为参数,我必须计算它们之间的直线是否位于黑色图形内。

我使用直线方程开发了自己的解决方案,但我的结果与使用“专业”程序(例如 GIMP 甚至 MS Paint)不同。

这是我想要的示例:

alt text http://img411.imageshack.us /img411/788/img1q.png

但我的算法是这样做的:

替代文本http://img267.imageshack.us/img267/1908/img2d.png

*绿点不在图中,这是不可能的。

有什么想法吗?有人知道在“专业”应用程序中使用了哪些代码吗?

谢谢! 丹尼尔.

编辑:图像

I need to paint the line which links two points.

I am doing it, in Java. I receive two points as parameters and I have to calculate if the straight line between them, is inside the black figure.

I developed my own solution using the straight line equation, but my results are different than using the "professional" programs (such as GIMP or even MS Paint).

Here is a example of what I want:

alt text http://img411.imageshack.us/img411/788/img1q.png

But my algorithm does this:

alt text http://img267.imageshack.us/img267/1908/img2d.png

*The green point is out of the figure and this is not possible.

Any ideas? Anyone know which code is been using for this, in "professional" apps?

Thanks!
Daniel.

EDIT: Images

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

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

发布评论

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

评论(4

万劫不复 2024-09-12 19:07:09

看起来您正在截断而不是四舍五入到最近的像素。很难看清那些小的黑色墨水斑点。你能发布代码吗?

It looks like you are truncating instead of rounding to the nearest pixel. Difficult to see on those small black ink splotches. Could you post the code?

琴流音 2024-09-12 19:07:09

“专业”程序最有可能使用Bresenham 直线算法

"Professional" programs most likely use Bresenham's line algorithm.

烙印 2024-09-12 19:07:09

通常使用 Bresenham 算法绘制直线。我不明白你关于绿点不在图中的观点 - 有剪裁,以免浪费时间在可见区域之外绘制。

Straignt lines are drawn using Bresenham's algorithm usually. I didn't get your point about green point being out of the figure - there's clipping to not waste time drawing outside the visible area.

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