Plotting matrix-skewed ellipses

18 views (last 30 days)
Nicolas
Nicolas on 15 Aug 2014
Answered: pk Yu on 15 Apr 2019
Hello, I am trying to plot the unit circle and then applying a 2x2 matrix on this circle to skew it. The column vector x is defined as x = [x1; x2], where x1 and x2 are cos(θ) and sin(θ), respectively, and θ ∈ [0,2π). I have generated 1000 vectors equidistant between 0 and 2π and created the unit circle. The issue I have is when I attempt to apply the matrices. The code I have so far is below:
clear all
close all
clc
t=linspace(0,2*pi,1000);
x1=cos(t);
x2=sin(t);
x=[x1;x2];
plot(x1,x2);
------------
A1=[2 0;0 3];
plot(A1*x);
A2=[1 2;3 4];
plot(A2*x);
A3=[1 2;2 4];
plot(A3*x);
The code above the line correctly produces the unit circle. The rest of the code should skew the unit circle into an ellipse but I get a mess when trying to plot.
Thanks!

Answers (3)

Image Analyst
Image Analyst on 18 Aug 2014
Code for creating an ellipse is given in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_ellipse.3F
  2 Comments
Nicolas
Nicolas on 18 Aug 2014
Sorry, but this is not what I am looking for. The link you provide shows how to create an ellipse from provided data whereas I am trying to skew an existing circle into an ellipse.
Image Analyst
Image Analyst on 18 Aug 2014
What difference does it make how you get the ellipse. By the way, you're applying a rotation matrix to the circle. That's why you probably don't notice anything. Rotating a circle gives a circle. You're not skewing/shearing it.

Sign in to comment.


Maurizio Tognolini
Maurizio Tognolini on 28 Sep 2016
Edited: Maurizio Tognolini on 28 Sep 2016
I think I have the solution of your problem, maybe it is possible to do that more efficient....
clear all
close all
clc
t=linspace(0,2*pi,100);
x1=cos(t);
x2=sin(t);
x=[x1;x2];
A1=[1 2;3 4];
y = A1*x;
figure(1) subplot(2,2,1) plot(x1,x2); grid axis equal
subplot(2,2,2) plot(y(1,:), y(2,:)); grid axis equal

pk Yu
pk Yu on 15 Apr 2019
Try this:
A1=[2 0;0 3];
xe = chol(A1)*x;
plot(xe(1,:),xe(2,:))
Note: A matrix must be positive definite to define an ellipse.
Check the definition of a ellipse () and Cholesky factorization if you are interested in the theory behind it.

Community Treasure Hunt

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

Start Hunting!