Re: 2D Rotation of Rectangle?
- From: Eric Carlson <ecarlson@xxxxxxxxxxxxxx>
- Date: Fri, 09 Sep 2005 13:21:18 -0500
JPhilson wrote:
Hi,
I was wondering if there is a way to rotate a 2D rectangle that I have plotted using the rectangle() command.
I have tried using rotate(), but it doesn't seem to like rectagle objects. I didn't notice any xData/yData properties under the rectangle object either, so I don't think I can simply hit the data points with a rotation matrix.
Thanks for any suggestions.
Hello, Since you know what a rotation matrix is, I would offer this suggestion:
rect.vertices=[0 0;1 0; 1 1; 0 1]; %square rect.faces=[1 2 3 4]; %connect vertices %rotation matrix theta = pi/4; R=[cos(theta) sin(theta);-sin(theta) cos(theta)]; S = [5 0; 0 1]; %Scaling for rectangle patch(rect,'Vertices',rect.vertices*S*R,'FaceColor',[1 0 0]); axis equal
The patch command is extremely versatile for drawing many 2D and 3D shapes, and I would recommend looking at it more carefully. There may very well be much simpler ways to draw and rotate a rectangle (you can box and rotate text with the text command, for example), but patch is much more interesting. You can add the rectangle to any figure without using the hold command. The coordinates should be in the data space, and if there is no data space (no current figure), the figure props will be adjusted to fit your polygon.
Cheers, Eric Carlson .
- References:
- 2D Rotation of Rectangle?
- From: JPhilson
- 2D Rotation of Rectangle?
- Prev by Date: how to discriminate edges
- Next by Date: Nonlinear Optimization
- Previous by thread: 2D Rotation of Rectangle?
- Next by thread: Pause in a Movie
- Index(es):
Relevant Pages
|