Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Feature Request: Add ofRectangle()::setRotateZ() #1966

Open
yty opened this Issue Mar 22, 2013 · 4 comments

Comments

Projects
None yet
3 participants

yty commented Mar 22, 2013

Rectangle rotation function,
And people did this function?

Contributor

kylemcdonald commented Mar 22, 2013

i'm not totally sure what you're proposing, could you provide a little more detail?

are you suggesting we make ofRectangle more like a cv::RotatedRect?

yty commented Apr 12, 2013

@kylemcdonald

sorry,my English is poor...View Code.

float angleZ;

void ofRectangle::setRotateZ(float _angleZ){
angleZ = _angleZ;
}

bool ofRectangle::inside(float tx, float ty) const {
bool over;

ofVec2f pos(x,y);
ofVec2f loc(tx,ty);
ofVec2f dirToCenter = pos - loc;
float theta = atan2(dirToCenter.x,dirToCenter.y)-(PI/2);
float r = dirToCenter.length();
float x = r * cos(theta + ofDegToRad( angleZ));
float y = r * sin(theta + ofDegToRad(angleZ));

if ((x <=  width * 0.5  ) && 
    (x >= -width * 0.5  ) && 
    (y <=  height * 0.5  ) && 
    (y >= -height * 0.5  ) ) 
    over = true;
else 
    over = false;

return over;

}

draw(){
ofPushMatrix();
ofTranslate(this->x,this->y);
ofRotateZ(this->angleZ);
ofRect(0,0,width,height);
ofPopMatrix();
}

In addition, And consider to ofRect Add angle

ofRect(int x,int y,int widht,int height,int angle);

Member

bakercp commented Apr 12, 2013

If we add Z rotation, then we really need a sense of anchor point (i.e. rotate Z around what?). Also, z-rotations start to complicate transformations and hit testing, alignment, etc. Why not X, Y, etc?

Anyway, in its current state I'd vote for keeping ofRectangle as a 2D non-rotatable object.

If we want to create rotated rectangles, I'd suggest an additional class (or subclass), or perhaps we could add add some utility functions to ofRectangle or ofPolyline ... something like

static ofPolyline ofMakeRotatedRectangle(const ofRectangle& rect, float rotateX, float rotateY, float Z);

Not an ideal solution.

Anyway, from my research on the last big ofRectangle updates, I think it's pretty standard practice to keep a base non-rotate-able rect class.

e.g.

http://qt-project.org/doc/qt-5.0/qtcore/qrect.html
http://msdn.microsoft.com/en-US/library/0kk0fzx6(v=vs.80).aspx
https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html
http://libcinder.org/docs/v0.8.4/classcinder_1_1_rect_t.html
etc.

Member

bakercp commented Apr 12, 2013

That said, I could definitely see the benefit of an openCV style ofRotatedRectangle.

It's a good topic to discuss @yty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment