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 comentarios

Guillaume
Guillaume el 8 de Ag. de 2019
Why do you think there's a mistake? Your parabola looks symmetric to me.
Ole
Ole el 8 de Ag. de 2019
Editada: Ole el 8 de Ag. de 2019
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
Bruno Luong el 8 de Ag. de 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 el 8 de Ag. de 2019
Editada: Ole el 8 de Ag. de 2019
Thank you!
The scaling was the issue.

Iniciar sesión para comentar.

Respuestas (1)

Jon
Jon el 8 de Ag. de 2019
Editada: Jon el 8 de Ag. de 2019

0 votos

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 comentario

Jon
Jon el 8 de Ag. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2016b

Etiquetas

Preguntada:

Ole
el 8 de Ag. de 2019

Comentada:

Jon
el 8 de Ag. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by