Rotation of curve question
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
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.
回答(1 个)
Jon
2019-8-8
编辑: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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!