Trying to draw arc given start point, end point and offsets to center
in
Programming Questions
•
1 year ago
I'm reading data that gives me the start and end points of a curve, and the X and Y offsets from the end point to the center of the arc. The data looks like this:
// FIRST POINT: X000.892787 Y000.303626
// SECOND POINT: X000.7555561 Y000.2055558 I-000.137122 J000.046827
where I is the offset from end point X to center X, and J is offset from end point Y to center Y.
The following is my test code to determine from this data the required elements for the arc() function, but I'm getting nothing. ANy suggestions as to what I'm missing or perhaps a better way to do this?
- float cx, cy, arcW, arcH, endAng, startAng;
- float scaleFactor = 200;
- float x1 = 000.7555561;
- float y1 = 000.2055558;
- float I1 = -000.137122;
- float J1 = 000.046827;
- float lastX = 000.892787;
- float lastY = 000.303626;
- void setup() {
- size(800,600);
- background(128);
- scale(1,-1);
- translate(100,-height*.75);
- stroke(255,0,0);
- cx = (x1*scaleFactor+I1*scaleFactor); //center = cx,cy
- cy = (y1*scaleFactor+J1*scaleFactor);
- arcW = ((I1*scaleFactor)*2)*-1; // width arxW - note: multiplied by -1 to make num positive
- arcH = (J1*scaleFactor)*2; // height arcH
- pushMatrix();
- translate(cx,cy); // reset origin to center to get angle using atan2() function
- endAng = atan2(y1*scaleFactor, x1*scaleFactor);
- startAng = atan2(lastY*scaleFactor, lastX*scaleFactor);
- popMatrix();
- arc(cx, cy, arcW, arcH, startAng, endAng); //draw resulting arc
- println("arc: "+cx+" "+cy+" "+arcW+" "+arcH+" "+startAng+" "+endAng);
- }
1