Rotation of curve question
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/233204/image.jpeg)
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 commentaires
Bruno Luong
le 8 Août 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.
Réponses (1)
Jon
le 8 Août 2019
Modifié(e) : Jon
le 8 Août 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 commentaire
Jon
le 8 Août 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.
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!