Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can someone please check my Matlab code to rotate a hyperbola and see what I am doing wrong

Posted on 2009-04-05
7
Medium Priority
?
832 Views
Last Modified: 2016-02-10
Please find the attached pdf tutorial for matlab and multilateration.

page 4. Please see code in the codebox below however when run it does not rotate the hyperbola as per the picture on page 4. It is in a different position?

Why is this?
% Program to plot the hyperbola
% y^2/a^2 - x^2/b^2 = 1
% The hyperbolae are open up/down, so that x is the independent variable
% for plotting. (Using the form x^2/a^2 - y^2/b^2 = 1 requires that y be
% the independent variable, which is awkward programming-wise.)
clear % all variables
figure(1), hold off % start a new figure
set(gca,'FontSize',14) % adjust fontsize
xmax = 30; ymax = 20;
x = linspace(-xmax,xmax,1001);
 
a = 5; b = 3;
theta=60*pi/180; % in radians, 1 radian = 180/pi degrees
xoff=10;
yoff=5;
y=sqrt(((x.^2)./(b^2)+1).*a^2); % corresponding y values
[xout,yout] = xfm1(x,y,theta,xoff,yoff); % rotation and shift
 
plot(xout,yout)
hold on % add to current plot
[xout,yout] = xfm1(x,-y,theta,xoff,yoff); % rotation and shift of negative part
plot(xout,yout) % Plot other half of hyperbola
 
axis([-xmax xmax -ymax ymax]) % specify axis limits
xlabel('x')
ylabel('y')
 
% Add axes
plot([0 0],[-ymax ymax],'k') % y axis
plot([-xmax xmax],[0 0],'k') % x axis
title(['Hyperbola $y^2/a^2 - x^2/b^2 = 1$; $a$ = ', num2str(a), ...
', $b$ = ', num2str(b),';'],'Interpreter','latex')
% Add axes
plot([0 0],[-ymax ymax],'k') % y axis (black line - k)
plot([-xmax xmax],[0 0],'k') % x axis

Open in new window

0
Comment
Question by:jtiernan2008
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:yuk99
ID: 24073370
I got almost the same figure as on your tutorial with this code without changing anything. I used the same xfm1 function file as we discussed before.
Do you get any figure with this code. If yes, how it's different from what you need? If no, do you get any errors?
0
 
LVL 1

Author Comment

by:jtiernan2008
ID: 24081290
thanks for your response

yes, I know I must be doing something wrong....
please see the attached with the code run and a screenshot from the tutorial.
It appears to not rotate the same.
pic.jpg
0
 
LVL 15

Expert Comment

by:yuk99
ID: 24081361
Change your rotation matrix in xfm1 function. I think we discussed this before. Change the sign for sines.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:yuk99
ID: 24081392
0
 
LVL 1

Author Comment

by:jtiernan2008
ID: 24081503
"BTW I think you made a wrong rotation matrix. No, it's correct, but rotate in not usual direction. It should be
xfm = [cos(theta) -sin(theta); ...
      sin(theta) cos(theta"

=> But it is the same as you can see below;
function [xout,yout] = xfm1(xin,yin,theta,x_offset,y_offset)
% Program to rotate and translate x,y values from x",y" to x,y space.
% Written to plot hyperbolas for time of arrival code.
% theta value assumed to be in radians.
 
%  rotation matrix
xfm = [cos(theta) -sin(theta); ...
      sin(theta) cos(theta)];
% make x,y values into a column vector
r_in = [xin; yin];
% rotate 
r_out = xfm*r_in;
x = r_out(1,:); y = r_out(2,:);
xout = x + x_offset; 
yout = y + y_offset;

Open in new window

0
 
LVL 15

Accepted Solution

by:
yuk99 earned 2000 total points
ID: 24081599
Usually positive angles rotate counterwise, negative clockwise. If you want opposite direction, just change both sines signes in rotatino matrix, or use negative angle. Again line along y axis has 0 degree.
0
 
LVL 1

Author Closing Comment

by:jtiernan2008
ID: 31566782
thanks a million..
I understand now
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question