Quantcast
Viewing all articles
Browse latest Browse all 4929

rotateRad() on ofVec2f not going full circle

@ConnectedCat wrote:

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:Image may be NSFW.
Clik here to view.
Annotation%202019-03-09%20214010

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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles