Skip to content

Instantly share code, notes, and snippets.

@ali1234
Last active July 4, 2022 22:10
Show Gist options
  • Save ali1234/84c55bf005002b9df8af76768416173e to your computer and use it in GitHub Desktop.
Save ali1234/84c55bf005002b9df8af76768416173e to your computer and use it in GitHub Desktop.
Convexity
Convexity
---------
Explanation for mathematicians:
1. Every object in OpenSCAD must be closed. An object is closed if it partitions space into two regions:
"inside" (the object itself) and "outside" (the rest of the empty space that the object does not occupy).
For the purposes of understanding convextity, we can ignore positions that lie exactly on the object's surface,
and say that any arbitrarily selected position in space must be either inside or outside the object - never both.
2. Every object in OpenSCAD must be finite. This just means that the object cannot stretch to infinity. The inside
of the object must fit within some arbtrarily large but finite bounding box.
3. A ray is an infinite length straight line in space. A ray intersects an object if (and only if) it
intersects the *surface* of the object, due to (1). Once again, we can ignore tangents - rays that only skim
the surface of the object, as they aren't important to convexity.
4. A ray that intersects the object must always intersect the surface an even number of times
- because every time it enters the object, it must eventually leave it again, due to (2).
5. Convexity is the maximum number of times *any* ray can intersect the surface of an object, divided by 2. Put
another way, it is the maximum number of times a ray can enter the object *and also* it is the maximum number of
times a ray can leave the object. Those two numbers *must* be equal for any given ray, because of (4).
6. All of this holds mathematically in 2D and 3D, but in OpenSCAD, 2D objects are previewed by giving them a small
thickness so they can be previewed in 3D. Convexity only affects previews, not the final render, so 2D objects
must be considered to be 3D when working out their convexity.
7. (Graphical examples.)
Explanation for OpenGL programmers:
When an object is previewed, faces (triangles) pointing away from the camera are not drawn. Faces pointing towards the
camera are projected into screen space and rasterized to pixels. Each rasterized face will cover some arbitrary set of
pixels on the screen, and those sets may overlap depending on the original camera position. Convexity is the maximum
number of overlaps which can be produced at any single pixel using any arbitrary camera position.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment