How do I rotate a square /rectangle using line as the reference point? Thank you

2 ビュー (過去 30 日間)
Karina
Karina 2023 年 1 月 15 日
編集済み: Adam Danz 2023 年 1 月 23 日
clc
clear all
close all
polyin = polyshape([0 1 1 0],[0 0 10 10]); %original shape
c1=rotate(polyin,-1.64329,[1 0]);
[x,y]=centroid(polyin);
[x1,y1] = centroid(c1);
plot([polyin c1])
axis equal
hold on
plot(x,y,'r*',x1,y1,'r*')
hold off
  1 件のコメント
DGM
DGM 2023 年 1 月 15 日
Using what line? Using it as a reference in what way?

サインインしてコメントする。

回答 (1 件)

Adam Danz
Adam Danz 2023 年 1 月 15 日
編集済み: Adam Danz 2023 年 1 月 23 日
I believe you're asking how to rotate the polyshape about its centerpoint. If so, specify the reference point of rotation using the thrid argument in polyout = rotate(polyin,theta,refpoint). The center point is returned by centroid().
polyin = polyshape([0 1 1 0],[0 0 10 10]); %original shape
[x,y]=centroid(polyin); % center point
c1=rotate(polyin,-1.64329,[x,y]); % rotate about center point
[x1,y1] = centroid(c1);
plot([polyin c1])
axis equal
hold on
plot(x,y,'r*',x1,y1,'r*')
hold off

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by