2

I have a CubicCurve in Java which is defined by 4 control points. I can draw the resulting shape, but how can I receive efficient every point in a given resolution of this shape? By the way PathIterator "only" returns the control points but not the points of the curve itself.

Spektre
  • 49,595
  • 11
  • 110
  • 380
Thomas
  • 1,622
  • 17
  • 24
  • What is the reason to have array of curve points? For most of common tasks (to detect if point is on the curve, to find a point of intersection with line, to animate over a curve) there is a formula typically. – Nick Rassadin Apr 13 '16 at 09:15
  • In my case I want to use the curve data to apply a gamma correction based on this curve. So I need as much discrete points as possible. – Thomas Apr 13 '16 at 10:22
  • So here you really need not points but transfer function `newBrightness=f(oldBrightness)`. – Nick Rassadin Apr 13 '16 at 12:01
  • show the code where you are trying to get the PathIterator – gpasch Apr 13 '16 at 14:42
  • final PathIterator iterator = curve.getPathIterator(null); while( ! iterator.isDone() ) { final double[] coords = new double[6]; iterator.currentSegment(coords); logger.info(coords[0] + "x" + coords[1] + " " + coords[2] + "x" + coords[3] + " " + coords[4] + "x" + coords[5]); iterator.next(); } – Thomas Apr 13 '16 at 21:16

1 Answers1

0

2D parametric cubic curves are just two polynomials

 x(t)=ax0+ax1*t+ax2*t*t+ax3*t*t*t
 y(t)=ay0+ay1*t+ay2*t*t+ay3*t*t*t

where t=<0.0,1.0> so you compute the a?0...a?3 coefficients from control points and then just loop t with as small step as you need to get all the points you need for example dt=1.0/(n-1) where n is the number of points.

The coefficients depends on curve used for BEZIER/SPLINE or interpolation see:

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • I am afraid the coefficients you are using in the formula are not the same as used for the CubicCurve in Java: https://docs.oracle.com/javase/7/docs/api/java/awt/geom/CubicCurve2D.html#constructor_summary – Thomas Apr 13 '16 at 21:45
  • @Thomas Then use what you have ... If you can then extract the coefficients from the shape you do not need to compute them. The polynomial equations `x(t),y(t)` will be the same. The only thing that could change is the interval of `t` – Spektre Apr 14 '16 at 06:21