Hi Chris,
Web Query wrote:
I was wondering if there was a way for Batik to take a rather complex
path and split it into two paths at a specified point. Here is the
situation:
The short answer is no. The longer answer is possibly shortly.
As part of implementing the new flowText element (which supports
flow into arbitrary regions). I have developed a sort of 'geometry
library'. This does not do exactly what you are looking for but
would be a big help.
I have a very complex path composed of many curves and lines that needs
to be split up into segments at specified points. So I have created a
Batik-based program that allows me to select a path and return to me the
point at which I selected the path. At this selected point I would like
to split the path into two path segments.
Can Batik do this? If not, is there a good algorithm for doing this?
Basically you need to learn how to subdivide a cubic bezier at
a particular 'time':
/**
* Subdivides this Cubic curve into two curves at given t.
* @param c0 if non-null contains portion of curve from 0->t.
* @param c1 if non-null contains portion of curve from t->1.
*/
public void subdivide(double t, Cubic c0, Cubic c1) {
if ((c0 == null) && (c1 == null)) return;
Point2D.Double np = eval(t);
Point2D.Double npd = evalDt(t);
if (c0 != null) {
c0.p1.x = p1.x;
c0.p1.y = p1.y;
c0.p2.x = (p2.x+p1.x)*t;
c0.p2.y = (p2.y+p1.y)*t;
c0.p3.x = np.x-(npd.x*t/3);
c0.p3.y = np.y-(npd.y*t/3);
c0.p4.x = np.x;
c0.p4.y = np.y;
}
if (c1 != null) {
c1.p1.x = np.x;
c1.p1.y = np.y;
c1.p2.x = np.x+(npd.x*(1-t)/3);
c1.p2.y = np.y+(npd.y*(1-t)/3);
c1.p3.x = (p4.x+p3.x)*(1-t);
c1.p3.y = (p4.y+p3.y)*(1-t);
c1.p4.x = p4.x;
c1.p4.y = p4.y;
}
}
public Point2D.Double evalDt(double t) {
double x = 3*( (p2.x-p1.x)*(1-t)*(1-t) +
2*(p3.x-p2.x)*(1-t)*t +
(p4.x-p3.x)*t*t);
double y = 3*( (p2.y-p1.y)*(1-t)*(1-t) +
2*(p3.y-p2.y)*(1-t)*t +
(p4.y-p3.y)*t*t);
return new Point2D.Double(x, y);
}
public Point2D.Double eval(double t) {
double x = ((1-t)*(1-t)*(1-t)*p1.x +
3*(t* (1-t)*(1-t)*p2.x +
t* t* (1-t)*p3.x) +
t*t*t *p4.x);
double y = ((1-t)*(1-t)*(1-t)*p1.y +
3*(t* (1-t)*(1-t)*p2.y +
t* t* (1-t)*p3.y) +
t*t*t *p4.y);
return new Point2D.Double(x, y);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]