0

I'm stuck in my Java awt development by some Maths.

I need to put SVG's Path command into a path from awt. Everything works nicely, but then I ran into the ArcTo command, and I still can't make it right.

AWT's ArcTo command needs the x and y coordinates, width and height of the Rectangle that will contain the Arc, an angleStart, the angle extent of the arc, and the type of arc-ending(irrelevant).

new Arc2D.Double(x, y, w, h, start, extent, type);

SVG's ArcTo command is nothing but that. Svg gives the X and Y radii of the arc, a rotation, two booleans(flags) and a targetPoint. The two flags are used to chose between the four possibilities of arcs left by the other parameters. This link shows nicely how it's done.

A rx ry x-axis-rotation large-arc-flag sweep-flag x y

JavaFX's ArcTo Command works barely like that,

new ArcTo(radiusX, radiusY, xAxisRotation, arcExtent, arcY, largeArcFlag, sweepFlag);

My Maths are not good enough to do such a conversion between those two constructors. I'll continue my research but I'm really lost rigth now, I really need your help!

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Kwarthys
  • 11
  • 5
  • [Here](http://hg.openjdk.java.net/openjfx/9-dev/rt/file/51d33b49c088/modules/javafx.graphics/src/main/java/javafx/scene/shape/ArcTo.java#l432) is the OpenJFX source code. The `private addArcTo` method does exactly that computation. – ccprog May 30 '17 at 17:17
  • SVG arcs can be rotated GDI style (like your Arc2D) can not. If you can apply matrices on gfx then you can convert SVG arc to axis aligned elliptic arc + transform matrix that converts it to the desired arc ... not easy to do ... but still doable (converting aspect ratio from ellipse to circle compute and convet back to ellipse helps a lot ... btw in the SVG docs there are equations for SVG arcs. If transfrorm matrices are not an option you need to convert arcs to polylines but that lose information ... See [Converting an svg arc to lines](https://stackoverflow.com/a/41544540/2521214) – Spektre May 31 '17 at 05:56
  • @ccprog Thanks a lot, that did the job like a charm. Some minor adapting were required but result is perfect. Too much maths for me. – Kwarthys May 31 '17 at 08:36

1 Answers1

0

I use the batik SVG libray to implement SVG graphics. You could you batik's ExtendedGeneralPath which has an arcTo() method which has exactly the same arguments in the same order as the SVG path command. For example, the following gives me a heart shape when you draw the path XX:

    ExtendedGeneralPath XX = new ExtendedGeneralPath();

    XX.moveTo(10, 30);
    XX.arcTo(20, 20, 0, false, true, 50, 30);
    XX.arcTo(20, 20, 0, false, true, 90, 30);
    XX.quadTo(90, 60, 50, 90);
    XX.quadTo(10, 60, 10, 30);
    XX.closePath();