Finding startAngle and arcAngle to go to drawArc () Java Graphics

So I have queries from a database that uses SDO_GEOMETRY to create arcs and they are created using three sets of points: (xStart, yStart), (xCenter, yCenter), (xEnd, yEnd)

So, imagine the rainbow and center point are at the very top (shown as X2, Y2) Arc example: Now I'm trying to translate this to use drawArc () in Java Graphics. However drawArc () takes parameters and I am stuck with the startArc and arcAngle parameters and don't know how to calculate them.

I looked around and there are also "end angles" or "center corners" of the arc, not sure if this is the same and I haven't found a good source for how to calculate startArc and arcAngle. Anyone familiar with this? Please share and thanks!

+3


source to share


3 answers


This should help you with your parameter code, you can always include variables as long as they are not

enter image description here



useful links: http://jdrawing.sourceforge.net/doc/0.2.5/api/org/jdrawing/graphics/DrawArc.html http://www.java-examples.com/draw-arc-applet-window- example

+2


source


I am stuck with startArc and arcAngle parameters and have no idea how to calculate them.

There are many different ways to set the two arc parameters.

One way is to use 0 and 180, which means you start at the end point and draw an arc 180 degrees counterclockwise, back to the start point. (ie, from the API docs: Angles are interpreted to mean 0 degrees is at the "3 o'clock" position. A positive value indicates counterclockwise rotation, while a negative value indicates clockwise rotation)



So, I think the general code would be:

g.drawArc (x1, y2, x3 - x1, (y2- y1) * 2, 0, 180);

      

+1


source


An alternative usage drawArc

is to use QuadCurve2D (although not familiar with your geometry, this approach may be required if the points do not define symmetrical geometry). You will need to calculate the control point of the curve, which can be done using the Bezier curve equation

B(t) = (1-t)^2 * P0 + 2(1-t)tP1 + t^2 P2

      

Here B (t) is a point on the line. Checkpoint solution:

P1 = (B(t) - (1-t)^2 * P0 - t^2 P2)/2(1-t)t

      

For the center point t = 0.5:

//example points, assuming center is at 0.5
int[] p1 = {100,50};
int[] center = {200,100};
int[] p3 = {300,50};
double x = (center[0] - Math.pow(0.5, 2) * p1[0] - Math.pow(0.5, 2) * p3[0] ) / (2*(0.5) * 0.5);
double y = (center[1] - Math.pow(0.5, 2) * p1[1] - Math.pow(0.5, 2) * p3[1] ) / (2*(0.5) * 0.5);
QuadCurve2D curve = new QuadCurve2D.Double(p1[0], p1[1], x, y, p3[0], p3[1]);
g.draw(curve);

      

The above expressions clearly demonstrate for demonstration, but can be simplified with the constants k Math.pow

and denominator

.

+1


source







All Articles