Rotation of curve question

5 views (last 30 days)
Ole
Ole on 8 Aug 2019
Commented: Jon on 8 Aug 2019
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 Comments
Bruno Luong
Bruno Luong on 8 Aug 2019
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
Ole on 8 Aug 2019
Edited: Ole on 8 Aug 2019
Thank you!
The scaling was the issue.

Sign in to comment.

Answers (1)

Jon
Jon on 8 Aug 2019
Edited: Jon on 8 Aug 2019
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 Comment
Jon
Jon on 8 Aug 2019
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.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!