随机曲线仅由点组成

时间:2012-12-18 18:11:02

标签: java math graphics2d splines

我需要创建一个这样的随机曲线:

A random curve

在这张图片中有3个例子,标记如下:

  1. 红色椭圆形是曲线的开头,
  2. 蓝色椭圆形表示结束。
  3. 他们之间是标有绿色椭圆的点。
  4. 我只能使用Point,因为在制作其中之一后,我需要为前一曲线中的每个Point创建另一条小曲线。我尝试使用sin函数或cos函数,但如果起点和终点的x或y点相同,它就会有效。

    有没有人知道如何使用Graphics2D和Point?

1 个答案:

答案 0 :(得分:3)

您应该使用Bezier Curves

如果您的曲线上的每个x值都有y值,那么您可以查看apache commons implementation。你得到的是PolynomialSplineFunction,你可以用来计算你曲线上的任何一点。

SplineInterpolator interpolator = new SplineInterpolator();
PolynomialSplineFunction f 
         = interpolator.interpolate(xValues, yValues); //red and blue dots
f.value(4.0); //gets y-value for  x = 4.0