首页 > 解决方案 > 在 MATLAB 中用复数绘制圆

问题描述

我想在 MATLAB 中制作一个图形,如下图所述在此处输入图像描述

我所做的是以下内容:

x = [1 2 3];
y = [2 2 4];
radius = [1 1.2 2.2];
theta = [-pi 0 pi];
figure;
scatter(x,y,radius)

如何在绘图中添加角度 theta 以表示z = radius.*exp(1j*theta)每个空间坐标处的复数?

标签: matlab

解决方案


从技术上讲,如果 x 和 y 轴等比例缩放,这些只是圆圈。那是因为scatter总是绘制圆圈,独立于比例(如果你不均匀地放大,它们仍然是圆圈。+你的线有问题,它应该指示角度......

您可以通过绘制圆圈来解决这两个问题:

function plotCirc(x,y,r,theta)
% calculate "points" where you want to draw approximate a circle
ang = 0:0.01:2*pi+.01; 
xp = r*cos(ang);
yp = r*sin(ang);
% calculate start and end point to indicate the angle (starting at math=0, i.e. right, horizontal)
xt = x + [0 r*sin(theta)];
yt = y + [0 r*cos(theta)];
% plot with color: b-blue
plot(x+xp,y+yp,'b', xt,yt,'b'); 
end

有了这个小函数,你可以调用它来绘制任意数量的圆圈

x = [1 2 3];
y = [2 2 4];
radius = [1 1.2 2.2];
theta = [-pi 0 pi];

figure
hold on
for i = 1:length(x)
    plotCirc(x(i),y(i),radius(i),theta(i))
end

在此处输入图像描述


推荐阅读