Plotting matrix-skewed ellipses

4 次查看(过去 30 天)
Nicolas
Nicolas 2014-8-15
回答: pk Yu 2019-4-15
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!

回答(3 个)

Image Analyst
Image Analyst 2014-8-18
Code for creating an ellipse is given in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_ellipse.3F
  2 个评论
Nicolas
Nicolas 2014-8-18
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 2014-8-18
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.

请先登录,再进行评论。


Maurizio Tognolini
Maurizio Tognolini 2016-9-28
编辑:Maurizio Tognolini 2016-9-28
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 2019-4-15
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