Reputation: 1
I have a 3D plot and I want to put a sphere in a designed position. How can I create a sphere? I expected to use patch? Can anyone help me to do this please?
Upvotes: 0
Views: 5631
Reputation: 6424
You can follow this:
Consider the center is at [c1,c2,c3]
. The number of faces as 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.
For instance, if C=[2,2,2]
and r=30
the result is as follows:
This is a sphere of radius 1
centered at [2,2,2]
. To have a sphere with an arbitrary radius R
, you should multiply the [x,y,z]
values by R
before adding the center.
Upvotes: 0