Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

sphere

创建球面

说明

示例

[X,Y,Z] = sphere 返回球面的 x、y 和 z 坐标而不对其绘图。返回的球面的半径等于 1,由 20×20 个面组成。

该函数以三个 21×21 矩阵形式返回 x、y 和 z 坐标。

要使用返回的坐标绘制球面,请使用 surfmesh 函数。

示例

[X,Y,Z] = sphere(n) 返回半径等于 1 且包含 n×n 个面的球面的 x、y 和 z 坐标。该函数以三个 (n+1)×(n+1) 矩阵形式返回 x、y 和 z 坐标。

示例

sphere(___) 绘制球面而不返回坐标。请将此语法与上述语法中的任何输入参数结合使用。

示例

sphere(ax,___) 将图形绘制到 ax 指定的坐标区中,而不是当前坐标区中。指定坐标区作为第一个输入参数。

示例

全部折叠

创建并绘制一个半径等于 1 的球面。使用 axis equal 可沿每个坐标方向使用相等的数据单位。

sphere
axis equal

Figure contains an axes object. The axes object contains an object of type surface.

通过修改返回的 XYZ 坐标来指定球面的半径和位置。

XYZ 定义为单位球面的坐标。

[X,Y,Z] = sphere;

以原点为中心绘制单位球面。

surf(X,Y,Z)
axis equal

Figure contains an axes object. The axes object contains an object of type surface.

通过乘以单位球面的坐标,将 X2Y2Z2 定义为半径为 5 的球面的坐标。以 (5,-5,0) 为中心绘制第二个球面。

hold on
r = 5;
X2 = X * r;
Y2 = Y * r;
Z2 = Z * r;

surf(X2+5,Y2-5,Z2)

Figure contains an axes object. The axes object contains 2 objects of type surface.

调用 tiledlayout 函数以创建 2×2 分块图布局。调用 nexttile 函数来创建坐标区。然后,使用 sphere 函数,通过指定坐标轴,将三个具有不同面数的球面绘制到图的不同图块中。

tiledlayout(2,2);
ax1 = nexttile;
sphere(ax1);
axis equal
title('20-by-20 faces (Default)')

ax2 = nexttile;
sphere(ax2,50)
axis equal
title('50-by-50 faces')

ax3 = nexttile;
sphere(ax3,100)
axis equal
title('100-by-100 faces')

Figure contains 3 axes objects. Axes object 1 with title 20-by-20 faces (Default) contains an object of type surface. Axes object 2 with title 50-by-50 faces contains an object of type surface. Axes object 3 with title 100-by-100 faces contains an object of type surface.

输入参数

全部折叠

面的数量,指定为正整数。

目标坐标区,指定为 Axes 对象。如果未指定坐标区,则 sphere 在当前坐标区中绘图。

版本历史记录

在 R2006a 之前推出

另请参阅

| | |