double s = l / 2;
Vector edgeDirection = MathUtils.getVector(start.getPoint(),
end.getPoint());
edgeDirection = MathUtils.normalize(edgeDirection);
Point centerPoint = MathUtils.getPointOfStraightLine(start.getPoint(),
edgeDirection, s);
Vector centerPointDirection = MathUtils.crossProduct(edgeDirection,
this.getExtrusion().getNormal());
centerPointDirection = MathUtils.normalize(centerPointDirection);
// double t = Math.sqrt(Math.pow(r, 2) - Math.pow(s, 2));
// double t = 0;
double h = Math.abs(start.getBulge() * l) / 2;
// if(Math.abs(start.getBulge())>=1.0){
// t = h-r;
// }else{
// //t = Math.sqrt(Math.pow(r, 2) - Math.pow(s, 2));
// t=r-h;
// }
// the center point of the arc
int startQ = 0;
int endQ = 0;
double bulge = start.getBulge();
if (bulge > 0) {
// the arc goes over the right side, but where is the center
// point?
if (bulge > 1.0) {
double t = h - r;
centerPoint = MathUtils.getPointOfStraightLine(centerPoint,
centerPointDirection, t);
} else {
double t = r - h;
centerPoint = MathUtils.getPointOfStraightLine(centerPoint,
centerPointDirection, (-1 * t));
}
endQ = MathUtils.getQuadrant(end.getPoint(), centerPoint);
startQ = MathUtils.getQuadrant(start.getPoint(), centerPoint);
} else {
// the arc goes over the left side, but where is the center
// point?
if (bulge < -1.0) {
double t = h - r;
centerPoint = MathUtils.getPointOfStraightLine(centerPoint,
centerPointDirection, (-1 * t));
} else {
double t = r - h;
centerPoint = MathUtils.getPointOfStraightLine(centerPoint,
centerPointDirection, t);
}
startQ = MathUtils.getQuadrant(end.getPoint(), centerPoint);
endQ = MathUtils.getQuadrant(start.getPoint(), centerPoint);
}
if (endQ < startQ) {
endQ += 4;
} else if ((endQ == startQ) &&
(Math.abs(start.getBulge()) > QUARTER_CIRCLE_ANGLE)) {
endQ += 4;
}
while (endQ > startQ) {
switch (startQ) {
case 0:
bounds.addToBounds(centerPoint.getX(),
centerPoint.getY() + r, centerPoint.getZ());
break;
case 1:
bounds.addToBounds(centerPoint.getX() - r,
centerPoint.getY(), centerPoint.getZ());
break;
case 2:
bounds.addToBounds(centerPoint.getX(),
centerPoint.getY() - r, centerPoint.getZ());
break;
case 3:
bounds.addToBounds(centerPoint.getX() + r,
centerPoint.getY(), centerPoint.getZ());
endQ -= 4;
startQ -= 4;
break;
}