[英]How to draw a sphere in matlab and patch it in a 3D plot?
I have a 3D plot and I want to put a sphere in a designed position. 我有一个3D图,我想在设计位置放置一个球体。 How can I create a sphere?
如何创建球体? I expected to use patch?
我希望使用补丁? Can anyone help me to do this please?
谁能帮我做到这一点?
You can follow this: 您可以遵循以下步骤:
Consider the center is at [c1,c2,c3]
. 考虑中心在
[c1,c2,c3]
。 The number of faces as r
. 面数为
r
。
[x,y,z] = sphere(r);
surf(x+c1, y+c2, z+c3)
These two lines of code are enough to plot a sphere using the surf
command. 这两行代码足以使用
surf
命令绘制球体。
For instance, if C=[2,2,2]
and r=30
the result is as follows: 例如,如果
C=[2,2,2]
且r=30
则结果如下:
This is a sphere of radius 1
centered at [2,2,2]
. 这是一个以
[2,2,2]
为中心的半径1
的球面。 To have a sphere with an arbitrary radius R
, you should multiply the [x,y,z]
values by R
before adding the center. 要使球体具有任意半径
R
,您应在将[x,y,z]
值乘以R
后再加上中心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.