Cylinder
ライブエディター
function Canvas() { const geo = cylinder({ radiusTop: 0.5, radiusBottom: 0.5, height: 1 }) const mat = rotate3dX(iDrag.y).mul(rotate3dY(iDrag.x)) const gl = useGL({ isWebGL: true, isDepth: true, count: geo.count, vertex: vec4(mat.mul(geo.vertex), 1), fragment: vec4(varying(geo.normal), 1), }) return <canvas ref={gl.ref} /> }
結果
Loading...
Cylinder Props
| radiusTop | Radius of the cylinder at the top. Default is 1. |
|---|---|
| radiusBottom | Radius of the cylinder at the bottom. Default is 1. |
| height | Height of the cylinder. Default is 1. |
| radialSegments | Number of segmented faces around the circumference. Default is 32. |
| heightSegments | Number of rows of faces along the height. Default is 1. |
| openEnded | Whether the ends of the cylinder are open or capped. Default is false. |
| thetaStart | Start angle for first segment in radians. Default is 0. |
| thetaLength | Central angle of the circular sector in radians. Default is Math.PI * 2. |
Parametric Surface Definition
The cylinder surface is defined as a parametric equation where the radius varies linearly along the height:
For parameters where represents angular position and represents height position:
Normal Vector Calculation
Surface normals are computed considering the slope between top and bottom radii:
The unnormalized normal vector at any point is: