Class Sphere
- java.lang.Object
-
- renderer.scene.Model
-
- renderer.models_L.Sphere
-
- All Implemented Interfaces:
MeshMaker
public class Sphere extends Model implements MeshMaker
Create a wireframe model of a sphere centered at the origin.See https://en.wikipedia.org/wiki/Sphere
A sphere of radius
ris the surface of revolution generated by revolving a half-circle in the xy-plane with radiusrand center(0,0,0)around the y-axis.Here are parametric equations for the right half-circle in the xy-plane with radius
rand center(0,0,0), parameterized from the top down.
Here is the 3D rotation matrix that rotates around the y-axis byx(phi) = r * sin(phi) \ y(phi) = r * cos(phi) |- 0 <= phi <= PI z(phi) = 0 /thetaradians,0 <= theta <= 2*PI
If we multiply the rotation matrix with the half-circle parameterization, we get a parameterization of the sphere.[ cos(theta) 0 sin(theta)] [ 0 1 0 ] [-sin(theta) 0 cos(theta)]
See https://en.wikipedia.org/wiki/Sphere#Equations_in_three-dimensional_space[ cos(theta) 0 sin(theta)] [r * sin(phi)] [ 0 1 0 ] * [r * cos(phi)] [-sin(theta) 0 cos(theta)] [ 0 ] = ( r * sin(phi) * cos(theta). \ r * cos(phi), |- 0<=theta<=2*PI, 0<=phi<=PI -r * sin(phi) * sin(theta) ) /- See Also:
SphereSector
-
-
Field Summary
Fields Modifier and Type Field Description intkintndoubler-
Fields inherited from class renderer.scene.Model
colorList, name, primitiveList, vertexList, visible
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetHorzCount()intgetVertCount()Sphereremake(int n, int k)Build an instance of theModelwith new values for the number of lines of latitude and longitude while keeping all the other model parameters the same.-
Methods inherited from class renderer.scene.Model
addColor, addPrimitive, addVertex, getPrimitive, toString
-
-
-
-
Constructor Detail
-
Sphere
public Sphere()
Create a sphere of radius 1 centered at the origin.
-
Sphere
public Sphere(double r)
Create a sphere of radiusrcentered at the origin.- Parameters:
r- radius of the sphere
-
Sphere
public Sphere(double r, int n, int k)
Create a sphere of radiusrcentered at the origin.The last two parameters determine the number of half circles of longitude and the number of circles of latitude in the model.
If there are
khalf circles of longitude, then each circle of latitude will havekline segments. If there arencircles of latitude, then each half circle of longitude will haven+1line segments.There must be at least three half circles of longitude and at least one circle of latitude.
- Parameters:
r- radius of the spheren- number of circles of latitudek- number of half circles of longitude- Throws:
IllegalArgumentException- ifnis less than 1IllegalArgumentException- ifkis less than 3
-
-
Method Detail
-
getHorzCount
public int getHorzCount()
- Specified by:
getHorzCountin interfaceMeshMaker- Returns:
- the number of lines of latitude that the
Modelcontains
-
getVertCount
public int getVertCount()
- Specified by:
getVertCountin interfaceMeshMaker- Returns:
- the number of lines of longitude that the
Modelcontains
-
-