rotateRad() on ofVec2f not going full circle


#1

I’m trying to rotate a point around a circle using rotateRad() and I seem to be missing something about how it’s supposed to work, because I only get 4 point instead of expected 6.
Here is the basic code:

ofVec2f center;
ofVec2f drawPoint;

center.set(ofGetWidth()/2, ofGetHeight()/2);
drawPoint.set(center.x + 100, center.y);

// and in draw()
ofSetColor(0, 0, 255);
ofNoFill();
ofDrawCircle(center, 100);

for (int i = 0; i < 6; i++) {
	ofSetColor(255, 0, 0);
	ofNoFill();

	float angle = TWO_PI / 6 * i;
	drawPoint.rotateRad(angle, center);

	std::cout << "Angle: " << angle << "\t\, Draw Point: " << drawPoint << endl;
	ofDrawLine(center, drawPoint);
	ofDrawBitmapString(ofToString(drawPoint), drawPoint );
}

There are two cycles that the function goes through (see below). On the first run the 2/3 PI (angle 2.0944) jumps to the point expected at PI, PI jumps back to original and the loop ends again at the point expected at PI. The second loop starts at the point expected at PI - the opposite of the first - and goes through similar jumps but in reverse and ends at 0. Here is the cout printout:

Angle: 0        , Draw Point: 612, 384
Angle: 1.0472   , Draw Point: 562, 470.603
Angle: 2.0944   , Draw Point: 412, 384
Angle: 3.14159  , Draw Point: 612, 384
Angle: 4.18879  , Draw Point: 462, 297.397
Angle: 5.23599  , Draw Point: 412, 384

Angle: 0        , Draw Point: 412, 384
Angle: 1.0472   , Draw Point: 462, 297.397
Angle: 2.0944   , Draw Point: 612, 384
Angle: 3.14159  , Draw Point: 412, 384
Angle: 4.18879  , Draw Point: 562, 470.603
Angle: 5.23599  , Draw Point: 612, 384

And the screenshot of the result:Annotation%202019-03-09%20214010

Am I wrong to expect it to go all around? What am I missing here?


#2

If you change ofDrawBitmapString to draw i (the point index) instead of the coordinates I think you will see what’s happening :slight_smile:

As a hint, rotateRad does not set the current rotation to the requested value, but it rotates the point starting at whatever rotation you already have.


#3

Blockquote
rotateRad does not set the current rotation to the requested value, but it rotates the point starting at whatever rotation you already have

This is not a hint, this is the explanation! Makes sense now, thank you!