从几个点绘制曲线

发布于 2024-11-15 11:09:15 字数 82 浏览 3 评论 0原文

我想知道如何将点连接在一起形成曲线。我的图表中有 20 个点,想知道如何连接它们。我尝试使用 GeneralPath 对象,但想知道是否有更好的方法?

I would like to know how to join point together to form a curve. I have 20 points in a diagram and would like to know how to join to them. I tried with GeneralPath object, but would like to know if there is a better way?

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

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

发布评论

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

评论(5

深海里的那抹蓝 2024-11-22 11:09:15

GeneralPath 当然是最直接的。创建路径,为第一个点调用 moveTo,然后为每个后续点调用 lineTo。然后将其绘制到 Graphics2D 对象。

GeneralPath is certainly the most straightforward. Create your path, call moveTo for your first point, then call lineTo for each subsequent point. Then draw it to a Graphics2D object.

只有影子陪我不离不弃 2024-11-22 11:09:15

听起来您需要 Catmull-Rom 曲线。请参阅http://www.mvps.org/directx/articles/catmull/更多详细信息,以及 http://johnsogg.blogspot.com/2010/01/cardinal-splines-and-catmull-rom.html 进行实现。

It sounds like you need a Catmull-Rom curve instead. See http://www.mvps.org/directx/articles/catmull/ for more details, and http://johnsogg.blogspot.com/2010/01/cardinal-splines-and-catmull-rom.html for an implementation.

淡莣 2024-11-22 11:09:15

GeneralPath 是一种很好的方法,应该可以很好地满足您的要求,除非您遗漏了其他内容。 Path2D 是一个可以更精确的新类,但如果您不需要这种精度,那么它比 GeneralPath 没有任何优势。

GeneralPath is a fine approach and should handle your requirement just fine unless you are leaving something else out. Path2D is a new class that can be more precise but if you don't need that precision there is no advantage to it over GeneralPath.

ˇ宁静的妩媚 2024-11-22 11:09:15

贝塞尔想象了一条基于多项式元素的曲线:(

(a + b)^3 = a^3 + 3a^2*b + 3a*b^2 + b^3

^ 是“幂”而不是“XOR”)。他实际上用 t 替换了 a,用 1-t 替换了 b。因此公式将是 (t + (1 - t))^3 (是的,它等于 1)。

此时,我们的公式

t^3 + 3*t^2*(1-t) + 3*t*(1-t)^2 + (1-t)^3

有4部分。选择4点。

(x1,y1), (x2,y2), (x3,y3), (x4,y4)

现在,创建参数方程,将公式的每个部分乘以一个坐标,如下所示:

x(t) = t^3*x1 + 3*t^2*(1-t)*x2 + 3*t*(1-t)^2*x3 + (1-t)^3*x4
y(t) = t^3*y1 + 3*t^2*(1-t)*y2 + 3*t*(1-t)^2*y3 + (1-t)^3*y4

这是三次贝塞尔曲线的参数方程。

您想要 20 次方贝塞尔曲线吗? “简单地”开发(t + (1-t))^20

帕斯卡三角应该对你有帮助。

Bézier imagined a curve based on the polynomial element:

(a + b)^3 = a^3 + 3a^2*b + 3a*b^2 + b^3

(^ being "to the power" and not "XOR"). He actually replaced a by t and b by 1-t. So that the formula would be (t + (1 - t))^3 (Yes, it's equal to 1).

At this point, we have the formula

t^3 + 3*t^2*(1-t) + 3*t*(1-t)^2 + (1-t)^3

There are 4 parts. Choose 4 points.

(x1,y1), (x2,y2), (x3,y3), (x4,y4)

Now, create parametric equations, multiplying every part of the formula by a coordinate, like this:

x(t) = t^3*x1 + 3*t^2*(1-t)*x2 + 3*t*(1-t)^2*x3 + (1-t)^3*x4
y(t) = t^3*y1 + 3*t^2*(1-t)*y2 + 3*t*(1-t)^2*y3 + (1-t)^3*y4

This is the parametric equation of the cubic Bézier.

You want a 20th power Bézier? "simply" develop (t + (1-t))^20.

Pascal Triangle should help you.

诗化ㄋ丶相逢 2024-11-22 11:09:15

的 GeneralPath 方法

public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)

要构建曲线而不仅仅是直线,您可以使用创建贝塞尔曲线 。但是要计算控制点x1, y1, x2, y2,您需要进行一些数学计算,或者下载一些插值库。

您也可以检查这个问题,它有一个实现一些插值算法的源代码的链接。

To build a curve, and not just lines, you can use method of GeneralPath

public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)

which creates Bezier curve. But to calculate control points x1, y1, x2, y2 you need to put some maths, or download some interpolation library.

Also you can check this question, it has a links to source code implementing some interpolation algorithms.

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