Plotting matrix-skewed ellipses
조회 수: 6 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (3개)
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
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
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
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!