Constructive Solid Geometry
Rendering function
from fdray import *
def render(*args):
return Scene(
Camera(30, 30, view_scale=2),
LightSource((1, 30, 40), "white"),
Cylinder((0, 0, 0), (3, 0, 0), 0.02, Color("red")),
Cylinder((0, 0, 0), (0, 3, 0), 0.02, Color("green")),
Cylinder((0, 0, 0), (0, 0, 3), 0.02, Color("blue")),
*args,
).render(width=300, height=300)
sphere = Sphere(0, 0.8, Color("yellow", 0.5)).translate("0.5*y")
cube = Cube(0, 2, Color("cyan", 0.5)).translate("-0.5*y")
Union
render(Union(sphere, cube)) # or sphere + cube
Difference
render(Difference(sphere, cube)) # or sphere - cube
render(Difference(cube, sphere)) # or cube - sphere
Intersection
render(Intersection(sphere, cube)) # or sphere * cube
Merge
render(Merge(sphere, cube)) # or sphere | cube