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
r
is the surface of revolution generated by revolving a half-circle in the xy-plane with radiusr
and center(0,0,0)
around the y-axis.Here are parametric equations for the right half-circle in the xy-plane with radius
r
and 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 /
theta
radians,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 int
k
int
n
double
r
-
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 int
getHorzCount()
int
getVertCount()
Sphere
remake(int n, int k)
Build an instance of theModel
with 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 radiusr
centered at the origin.- Parameters:
r
- radius of the sphere
-
Sphere
public Sphere(double r, int n, int k)
Create a sphere of radiusr
centered 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
k
half circles of longitude, then each circle of latitude will havek
line segments. If there aren
circles of latitude, then each half circle of longitude will haven+1
line 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
- ifn
is less than 1IllegalArgumentException
- ifk
is less than 3
-
-
Method Detail
-
getHorzCount
public int getHorzCount()
- Specified by:
getHorzCount
in interfaceMeshMaker
- Returns:
- the number of lines of latitude that the
Model
contains
-
getVertCount
public int getVertCount()
- Specified by:
getVertCount
in interfaceMeshMaker
- Returns:
- the number of lines of longitude that the
Model
contains
-
-