【matlab程序】matlab画太极图|阴阳
时间: 2023-12-09 18:36:02 浏览: 170
以下是使用Matlab绘制太极图的代码和步骤:
1. 首先,我们需要定义一个半径为1的圆形,可以使用`rectangle`函数绘制一个正方形,再使用`ellipse`函数将其变成圆形。
```matlab
rectangle('Position',[-1,-1,2,2],'Curvature',[1,1],'FaceColor','w','EdgeColor','k');
hold on;
ellipse(1,1,0,0,1,'k');
```
2. 接下来,我们需要在圆形中心绘制两个小圆,表示阴阳两极。可以使用`rectangle`函数绘制两个正方形,再使用`ellipse`函数将其变成圆形。
```matlab
rectangle('Position',[-0.2,-0.2,0.4,0.4],'Curvature',[1,1],'FaceColor','k','EdgeColor','k');
rectangle('Position',[-0.2,0.8,0.4,0.4],'Curvature',[1,1],'FaceColor','w','EdgeColor','k');
ellipse(0.2,0.2,0,0,0.2,'k');
ellipse(0.2,1.2,0,0,0.2,'k');
```
3. 最后,我们需要在太极图中心绘制两个阴阳鱼图案。可以使用`patch`函数绘制多边形。
```matlab
theta = linspace(0,2*pi,100);
x1 = 0.6*cos(theta)-0.5;
y1 = 0.6*sin(theta)+0.5;
x2 = 0.6*cos(theta)+0.5;
y2 = 0.6*sin(theta)-0.5;
patch(x1,y1,'w','EdgeColor','k');
patch(x2,y2,'k','EdgeColor','k');
```
完整代码如下:
```matlab
rectangle('Position',[-1,-1,2,2],'Curvature',[1,1],'FaceColor','w','EdgeColor','k');
hold on;
ellipse(1,1,0,0,1,'k');
rectangle('Position',[-0.2,-0.2,0.4,0.4],'Curvature',[1,1],'FaceColor','k','EdgeColor','k');
rectangle('Position',[-0.2,0.8,0.4,0.4],'Curvature',[1,1],'FaceColor','w','EdgeColor','k');
ellipse(0.2,0.2,0,0,0.2,'k');
ellipse(0.2,1.2,0,0,0.2,'k');
theta = linspace(0,2*pi,100);
x1 = 0.6*cos(theta)-0.5;
y1 = 0.6*sin(theta)+0.5;
x2 = 0.6*cos(theta)+0.5;
y2 = 0.6*sin(theta)-0.5;
patch(x1,y1,'w','EdgeColor','k');
patch(x2,y2,'k','EdgeColor','k');
```
阅读全文