Draw an arc of a RING.

Hi there!

I’m trying to draw an arc of a RING, not a circle. In processing this is easy done with the arc() function that have an Mode where you can choose the type of arc. But i can’t find it in OF. Maybe there another way to do this.

Can anyone help me with this?
thanks
JF

ofPolyLine and ofPath have a similar function to processing…

  
  
ofPolyline curve;  
curve.arc(centre, radiusX, radiusY, startAngle, endAngle, arcResolution);  
curve.draw();  
  

Or you can code it manually…

  
  
vector<ofPoint> testApp::getArcPoints(ofVec2f centre, float radiusX, float radiusY, float startAngle, float endAngle, int arcResolution) {  
    int index = 0;  
    float startRad = ofDegToRad(startAngle);  
    float endRad = ofDegToRad(endAngle);  
    float res = ofDegToRad(360.0f/arcResolution);  
    int resizeTo = (endRad - startRad) / res + 1;  
    vector<ofPoint> points(resizeTo);  
    for(float i = startRad; i < endRad; i += res) {  
        points[index].x = cos(i) * radiusX + centre.x;  
        points[index].y = sin(i) * radiusY + centre.y;  
        index++;  
    }  
    return points;  
}  

1 Like

Hi trentbrooks!

thanks for the answer.

But the that will draw an arc of circle, i want to draw an arc of a ring(Like a slice of a donut).
Do you know if this is possible? is there any function to that in OF?

cheers
dot

Try this :

  
  
	ofPath curve;  
	ofPoint p(ofGetWindowWidth() / 2, ofGetWindowHeight() / 2);  
	curve.arc(p, 300, 300, 0, 210);  
	curve.arcNegative(p, 200, 200, 210, 0);  
	curve.close();  
	curve.setArcResolution(60);  
	ofColor c(255, 0,0);  
	curve.setFillColor(c);  
	curve.setFilled(true);  
	curve.draw();  
  

3 Likes