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

Open
opened this Issue Mar 22, 2013 · 4 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.
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!