Plotting matrix-skewed ellipses

조회 수: 6 (최근 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.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by