Plotting matrix-skewed ellipses

13 vues (au cours des 30 derniers jours)
Nicolas
Nicolas le 15 Août 2014
Réponse apportée : pk Yu le 15 Avr 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!

Réponses (3)

Image Analyst
Image Analyst le 18 Août 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 commentaires
Nicolas
Nicolas le 18 Août 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 le 18 Août 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.

Connectez-vous pour commenter.


Maurizio Tognolini
Maurizio Tognolini le 28 Sep 2016
Modifié(e) : Maurizio Tognolini le 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 le 15 Avr 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!

Translated by