Sphere¶
Qualified name: algan.mobs.shapes\_3d.Sphere
- class Sphere(center=tensor([0., 0., 0.]), radius=1, resolution=None, u_range=(0, 360), v_range=(0, 180), *args, **kwargs)[source]¶
Bases:
SurfaceA 3-D sphere, tessellated from a
Surface.Because it is a curved
Surfacerather than a fixed mesh, its silhouette is refined per frame to whatever the camera needs, so it stays round as you move in.- Parameters:
center – World-space location of the sphere’s center, shape
(*, 3)where*denotes zero or more batch dimensions. Python lists and floats are cast to tensors. Defaults toORIGIN(the world origin).radius – Radius in world units. Defaults to
1.resolution – Manim-style grid resolution as
(u_patches, v_patches), or one int for both. Manim counts patches and Algan counts sampled vertices, so each value is used asgrid_width/grid_heightplus one. Defaults toNone, meaning Algan sizes the grid itself fromgeometry_tolerance.u_range – Azimuthal sweep around the sphere’s own up axis, in degrees. The sweep starts at the sphere’s
LEFTand turns throughOUTWARD,RIGHTandINWARD, so(0, 180)builds theOUTWARDhalf – the one facing the camera. Defaults to(0, 360), all the way round.v_range – Pole-to-pole sweep, in degrees:
0is theDOWNpole and180theUPone.(0, 90)builds the bottom hemisphere,(45, 135)a band around the equator. Defaults to(0, 180), pole to pole.*args – Passed to
Surface– notablycolor,grid_width/grid_heightand the texture maps – notablycolor_texture, whichget_checkerboard()and its siblings build.**kwargs – Passed to
Surface– notablycolor,grid_width/grid_heightand the texture maps – notablycolor_texture, whichget_checkerboard()and its siblings build.
Notes
A partial
u_rangeorv_rangebuilds an open shell. The cut edges are not capped, so the inside of the surface shows through them, and the shape is re-tessellated from scratch rather than carved out of the whole sphere’s grid. The tessellation search only promisesgeometry_tolerance, and a sweep that still reaches a pole needs a finer grid there than a closed sphere does – so a partial sphere is not automatically the cheaper one.Examples
A blue sphere, sized in world units:
Example: Example1Sphere ¶
from algan import * Sphere(radius=0.8, color=BLUE).spawn() Scene.save_video()
A hemisphere, and a band around the equator:
Example: Example2Sphere ¶
from algan import * Sphere(radius=0.7, v_range=(0, 90), color=BLUE).move(LEFT * 0.9).spawn() Sphere(radius=0.7, v_range=(60, 120), color=YELLOW).move(RIGHT * 0.9).spawn() Scene.save_video()
Methods
Map the surface's
(u, v)parameters to positions in space.Attributes
animation_managerThis mob's scene-owned animation manager.
basisThe Mob's orientation and scale, as a flattened 3x3 matrix of shape
(*, 9).casts_shadowsWhether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.
childrenThe Mobs attached below this one, in attachment order.
closed_shellWhether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.
color_textureAn image painted across the surface, as an
[W, H, 5]RGBA+glow tensor.draws_descendantsWhether
get_render_primitivesreturns geometry belonging to this Mob's DESCENDANTS as well as its own.forwardGet the direction the Mob is facing.
geometry_toleranceHow far this surface's mesh may sit from the exact shape, in world units.
lifespanThis mob's [spawn, despawn) interval on its Scene timeline (a
Lifespan).locationThe Mob's position in world space, shape
(*, 3).normalized_basisThe Mob's orientation with scale divided out, shape
(*, 9).parentsThe Mobs this one is attached to, in attachment order.
receives_shadowsWhether this Mob's surfaces are darkened by shadows cast onto them.
render_tolerance_pixelsHow far a drawn triangle may sit from the true surface, in pixels.
rightGet the Mob's own rightward direction.
scale_coefficientThe Mob's scale along its own right, up and forward axes, shape
(*, 3).Whether this Mob's geometry should be lit from whichever side the ray arrives on.
upGet the Mob's own upward direction.
verticesThe surface's vertex positions, shape
(*, grid_width * grid_height, 3).xThe Mob's x coordinate in world units, shape
(*, 1).xyThe Mob's x and y coordinates in world units, shape
(*, 2).yThe Mob's y coordinate in world units, shape
(*, 1).zThe Mob's z coordinate in world units, shape
(*, 1).- coord_function(coords_2d)[source]¶
Map the surface’s
(u, v)parameters to positions in space.This is what defines the surface’s shape, and what each 3-D shape class overrides:
Spheremaps the unit square onto a sphere,Torusonto a torus, and so on. The base implementation gives a flat plane spanning[-1, 1]on both axes.- Parameters:
uv – Parameter coordinates to map, shape
(*, 2), with both components in[0, 1].- Returns:
Positions relative to the surface’s location, shape
(*, 3).- Return type:
torch.Tensor
- two_sided = False¶
Whether this Mob’s geometry should be lit from whichever side the ray arrives on.
True(the default) is for geometry with no meaningful outside – a 2-D shape,Text, a parametricSurface, an imported mesh whose winding nobody has checked – where a back-facing hit is shaded with its normal flipped toward the viewer, so the surface is lit from behind instead of coming out black.The built-in solids set it
False: their normals face out (seetests/unit_tests/test_normal_orientation.py), so a back-facing hit is genuinely the inside of the solid and is shaded as such. That is what stops a half-transparent solid’s far shell from being lit like a second front shell – the bright and dark “planes” through a fading Octahedron. Set itTrueon an instance to get the old two-sided lighting back (an openConeyou want lit inside, say); it must be set before the Mob is spawned, since the render primitive reads it once.