我需要创建一个这样的随机曲线:
在这张图片中有3个例子,标记如下:
我只能使用Point,因为在制作其中之一后,我需要为前一曲线中的每个Point创建另一条小曲线。我尝试使用sin函数或cos函数,但如果起点和终点的x或y点相同,它就会有效。
有没有人知道如何使用Graphics2D和Point?
答案 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