# Rotation of curve question

7 ビュー (過去 30 日間)
Ole 2019 年 8 月 8 日
コメント済み: Jon 2019 年 8 月 8 日
I am trying to rotate a curve about a point (yellow asterisk) and do not obtain a symmetric result.
Xr = (x-XXc)*cos(delta) + (yp-YYc)*sin(delta) + XXc;
Yr = - (x-XXc)*sin(delta) + (yp-YYc)*cos(delta) + YYc;
Where is the mistake ?
clear all; close all;clc;
ah=10; bh=1; ch = sqrt(ah^2+bh^2); % hyperbola
delta =10*pi/180; % rotation angle
XXc = 30; YYc = 0; % rotaion about point XXc, YYc
x = linspace(20, 40, 10000);
yp = bh*sqrt((x-10).^2/ah^2-1);
ym = - bh*sqrt((x-10).^2/ah^2-1);
Xr = (x-XXc)*cos(delta) + (yp-YYc)*sin(delta) + XXc;
Yr = - (x-XXc)*sin(delta) + (yp-YYc)*cos(delta) + YYc;
Xrm = (x-XXc)*cos(delta) + (ym-YYc)*sin(delta) + XXc;
Yrm = - (x-XXc)*sin(delta) + (ym-YYc)*cos(delta) + YYc;
xxcf0 = 10+ah; yycf0 = 0; %vertex
Xrm0 = (xxcf0-XXc)*cos(delta) + (yycf0-YYc)*sin(delta) + XXc;
Yrm0 = - (xxcf0-XXc)*sin(delta) + (yycf0-YYc)*cos(delta) + YYc;
figure(1)
plot(Xr,Yr,'r',Xrm,Yrm,'r', Xrm0,Yrm0,'*', [Xrm0 XXc],[Yrm0 YYc])
hold on
plot(x,yp,'b',x,ym,'b', XXc,YYc,'*',10+ah,0,'*')
hold off

#### 4 件のコメント

Ole 2019 年 8 月 8 日
The purple asterisk is the vertex of the non rotated curve. The blue asterisk should be the vertex of the new rotated curve.
The line between the yellow asterisk and the blue asterisk should be the new axis X'.
The curve is supposed to be symmetric around X'. It looks the rotated vertex (the blue asterisk) is not the vertex of the new rotated curve.
Bruno Luong 2019 年 8 月 8 日
Did not look (yet) your code but often if you do not run "axis equal" in the graphics you might be missleaded by the scaling.
Ole 2019 年 8 月 8 日
Thank you!
The scaling was the issue.

サインイン to comment.

### 回答 (1 件)

Jon 2019 年 8 月 8 日

I think you also have a sign error in your formula.
Xr = (x-XXc)*cos(delta) + (yp-YYc)*sin(delta) + XXc;
% should be
Xr = (x-XXc)*cos(delta) - (yp-YYc)*sin(delta) + XXc;
and
Xrm = (x-XXc)*cos(delta) + (ym-YYc)*sin(delta) + XXc;
% should be
Xrm = (x-XXc)*cos(delta) - (ym-YYc)*sin(delta) + XXc;
Also I would suggest taking advantage of MATLAB's ability to work directly with matrices and vectors and first define a rotation matrix R as
R = [cos(theta) -sin(theta);sin(theta) cos(theta)]
and then you can just use matrix vector multiplies for example defining your rotated vector Vr as
Vr = R*[x-XXc;yp-YYc] + [XXc;YYc]

#### 1 件のコメント

Jon 2019 年 8 月 8 日
Oh, sorry, never mind about the sign error. I see now that you are just rotating clockwise and have the negative term on the sin that is applied to x. I would still recommend using the rotation matrices though as it is more compact and makes the code much more readable.

サインイン to comment.

サインイン してこの質問に回答します。

R2016b

Translated by