필터 지우기
필터 지우기

How to rotate RECTANGLE?

조회 수: 35 (최근 30일)
Kevin
Kevin 2022년 4월 2일
댓글: Image Analyst 2022년 4월 3일
Hi everyone,
I am using the matlab function RECTANGLE to plot rectangle and ellipse in a figure.
Is it possible to rotate it by any angle (say 30 degrees)?
Kevin

채택된 답변

Walter Roberson
Walter Roberson 2022년 4월 2일
Not exactly, but there is a way.
h = rectangle('Position',[0 0 2 4],'Curvature',1);
g = hgtransform('Matrix', makehgtform('zrotate', pi/6))
g =
Transform with properties: Children: [0×0 GraphicsPlaceholder] Visible: on HitTest: on Matrix: [4×4 double] Show all properties
h.Parent = g;
xlim([-5 5]); ylim([-5 5])
Watch out for where the origin of the rotation is; if you want to rotate around the center of the object you should use a transform that subtracts the centroid, does the rotation, and adds back the centroid again. You will find that in practice the makehgtform() call for that will have the addition first, then the rotation, then the subtraction -- that is, the order of operations works out to be right to left.
  댓글 수: 2
Kevin
Kevin 2022년 4월 3일
Great. This works.
Image Analyst
Image Analyst 2022년 4월 3일
@Kevin I see this requested so often. Please send in a request to support@mathworks.com saying there should be an "Angle" option of rectangle() so we can specify the angle in degrees of the long sides.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by