sphere
Main Content
Description
example
returns the x-, y-, and z- coordinates of a sphere without drawing it. The returned sphere has a radius equal to and consists of by faces.
The function returns the x-, y-, and z- coordinates as three -by- matrices.
To draw the sphere using the returned coordinates, use the or functions.
example
returns the x-, y-, and z- coordinates of a sphere with a radius equal to and -by- faces. The function returns the x-, y-, and z- coordinates as three -by- matrices.
example
plots the sphere without returning the coordinates. Use this syntax with any of the input arguments in previous syntaxes.
example
plots into the axes specified by instead of the current axes. Specify the axes as the first input argument.
Examples
collapse all
Display Unit Sphere
Create and plot a sphere with a radius equal to 1. Use to use equal data units along each coordinate direction.
Specify Sphere Radius and Location
Specify the radius and location of a sphere by modifying the returned , , and coordinates.
Define , , and as coordinates of a unit sphere.
Plot the unit sphere centered at the origin.
Define , , and as coordinates of a sphere with a radius of 5 by multiplying the coordinates of the unit sphere. Plot the second sphere, centering it at .
Display Sphere with Different Numbers of Faces
Call the function to create a 2-by-2 tiled chart layout. Call the function to create the axes. Then, use the function to plot three spheres with different numbers of faces into different tiles of the chart by specifying the axes.
Input Arguments
collapse all
&#; Number of faces
positive integer
Number of faces, specified as a positive integer.
&#; Target axes
object
Target axes, specified as an object. If you do not specify the axes, then plots into the current axes.
Introduced before Ra
You have a modified version of this example. Do you want to open this example with your edits?
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office
Matlab sphere()
Introduction to Matlab sphere()
MATLAB incorporates the function sphere() which can be used to create a 3-D sphere. Since the function deals with a 3D graph, the output from the function is obtained with 3-axes co-ordinates.
Syntax:
The function sphere() in MATLAB, can be implemented in the code using any of the syntaxes described below. The syntaxes are developed based on input arguments and output arguments used to use the function.
Syntax | Attribute Description |
sphere | Creates a unit sphere i.e. a sphere with a radius of value 1. |
[X,Y,Z]=sphere | This syntax does not plot the graph rather it returns the x,y, and z coordinates of the sphere in the form of 21X21 matrices. |
[X,Y,Z]=sphere(n) | This syntax does not plot the graph rather it returns the x,y and z coordinates of the sphere in the form of (n+1)X(n+1) matrices. Where n represents the number of faces, consisted of the sphere. |
Sphere(&#;-) | Creates a unit sphere i.e. a sphere with being customized with the values given as input arguments in the function. |
Sphere(ax,&#;-) | Creates a unit sphere i.e. a sphere with being customized with the values given as input arguments in the function with the given new co-ordinates ax. |
Examples of Matlab sphere()
Following are the examples are given below:
Example #1
Output:
The above code results in creating a unit plot with a uniform axis setting.
The attributes that are supported by sphere()
There are two input arguments that can be used while implementing the function sphere.
Attribute | Description |
Number of Faces (n) | Used to decide the number of faces to use with the sphere plot |
Target axes (ax) | Used to define new axes object |
Usage of different syntax, attributes, and resultant behavior from the function call is described in the examples defined below:
Example #2
Using the syntax sphere
In the below code the 3D sphere plotting function is called using the syntax ‘sphere’.
Output:
The command generates a unit sphere i.e. a sphere with a radius of value ‘1’.
Example #3
Using the syntax [X, Y, Z] =sphere
The below code snippet generate x, y, z coordinates in order to generate the sphere plot using the functions ‘surf’ or ‘mesh’.
Output:
The above command has generated p, q, and r-coordinates and is given as the value for the input argument, the center of the graph, to the function surf().
Example #4
Using the syntax [X,Y, Z] =sphere(n)
The below code snippet is defined to generate p, q, and r- coordinates using the function sphere with the value of n=
Output:
The value for the attribute n i.e. number of faces is set as 25 in the code. Hence it results in creating sphere with unit radius and by i.e. ((n+1)-by-(n+1)) faces.
Example #5
Using the syntax Sphere(&#;-)
The below code snippet generates a sphere with a unit radius with value for origin as an input argument (n=30) to the function sphere.
Output:
The above command generates a unit sphere with byi.e. ((n+1)-by-(n+1)) faces.
Example #6
Using the syntax Sphere(ax,&#;-)
The below code snippet generates a sphere with unit radius with value for origin and user-defined axes ‘px’ as an input argument to the function sphere.
Output:
The plot from the above command consists of a unit sphere in one of the cells of the 2X1 frame with a new axis ‘px’.
Creating a Sphere with Different Measurements for Radius and Origin Apart from Unity Value:
The 3D sphere plotting function sphere can be used to generate a sphere having a radius of value more than one and shifted origin measure.
Example:
The code snippet defined below generate a plot for the sphere with a radius of and origin at (,,)
Output:
Example:
The MATLAB code defined below to generate two spheres in the same plane having two different radius and origin.
Output:
The resultant plot contains a unit sphere having the origin at (0,0,0) and another sphere having radius of size 5 and origin at (5, -5,0).
Creating Multiple Spheres in Different Cells of A Single Layout
MATLAB supports creating a multiple numbers of 3D sphere plots single layout, representing each graph in a different cells of it.
Example:
The MATLAB code generates 4 different spheres displaying them in 4 segments of a single layout.
Output:
Setting Radius for Multiple Spheres from An Array/matrix Input
As we have discussed earlier, the function ‘sphere’ can also be used to create multiple spheres in a single layout. The radius and origin can be set differently for each of those spheres by declaring the radius values as an array or matrix.
The below code snippet is designed to create 3 different spheres with 3 different radius and origin defined an array.
Example:
Output:
Creating Transparent Sphere
The sphere generated from the MATLAB function ‘sphere’ can be made transparent by regulating the attribute value FaceAlpha.
The below example demonstrates the impact of the variations in the value of the attribute FaceAlphaon the transparency of a unit sphere that is created by the function ‘sphere’.
Example:
Case 1: With FaceAlpha =
Output:
Case 2: With FaceAlpha =
Output:
Thus MATLAB programming is supported by creating 3D sphere plots using the function sphere. The function also provides flexibility to customize the display of the plots during the creation as well as editing the display after the plot is created.
Recommended Articles
This is a guide to Matlab sphere(). Here we also discuss the Introduction and syntax of matlab sphere() along with different examples and code implementation. You may also have a look at the following articles to learn more &#;
- Matlab Plot Circle
- Matlab stem()
- MATLAB Derivative of Function
- Histogram in Matlab
- MATLAB Indexing | Top 5 Examples
- Matlab Figure | Examples
- Kalamazoo missed connections
- Ubiquiti aircube reviews
- Xfinity gaming speed
- Countif multiple columns
- Wrx wind deflectors
MATLAB Function Reference |
Generate sphere
Syntax
- sphere sphere(n) [X,Y,Z] = sphere()
Description
The function generates the x-, y-, and z-coordinates of a unit sphere for use with and .
generates a sphere consisting of by faces.
draws a plot of an -by- sphere in the current figure.
returns the coordinates of a sphere in three matrices that are -by- in size. You draw the sphere with or
Examples
Generate and plot a sphere.
- sphere axis equal
See Also
, equal
Polygons and Surfaces for related functions
sph2cart | spinmap |
© The MathWorks, Inc.
.
In plot matlab sphere
.
plot sphere of different radius and centre in MATLAB for beginners.
Similar news:
- Fidelity debit card
- Extendable shower head
- Jct tiller
- Funny videos tamil
- Bubble letter name plate
- 1960s mens fashion trends
.