From 370dea50603e9aa915e3752abbb428578f1f5eae Mon Sep 17 00:00:00 2001 From: raffitz Date: Sat, 3 Apr 2021 21:57:21 +0100 Subject: [PATCH] Add another tetrahedron and an octahedron --- README.md | 6 +- examples/hoctahedron1.solid | 25 +++++++++ examples/htetra2.solid | 107 ++++++++++++++++++++++++++++++++++++ examples/octahedron1.solid | 14 +++++ examples/tetrahedron2.solid | 97 ++++++++++++++++++++++++++++++++ 5 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 examples/hoctahedron1.solid create mode 100644 examples/htetra2.solid create mode 100644 examples/octahedron1.solid create mode 100644 examples/tetrahedron2.solid diff --git a/README.md b/README.md index aad084e..34b8883 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,11 @@ The output consists of a series of images, each depicting a layer of the solid, | `cube.solid` | Cube | A cube stood on its vertex | | `hcube.solid` | Hollow Cube | A hollow cube stood on its vertex | | `tetrahedron1.solid` | Tetrahedron | A tetrahedron stood on its edge | -| `htetra1.solid` | Hollow Teterahedron | A hollow tetrahedron stood on its edge | +| `htetra1.solid` | Hollow Tetrahedron | A hollow tetrahedron stood on its edge | +| `tetrahedron2.solid` | Tetrahedron | A tetrahedron stood on its base/vertex | +| `htetra2.solid` | Hollow Tetrahedron | A hollow tetrahedron stood on its base/vertex | +| `octahedron1.solid` | Octahedron | An octaheron stood on its vertex | +| `hoctahedron1.solid` | Hollow Octahedron | A hollow octahedron stood on its vertex | | `sphere.solid` | Sphere | A sphere of radius s | | `torus1.solid` | Torus | A torus with a tube radius of s, and a hole radius of 2 * s | | `ramp.solid` | Ramp | A spiraling ramp | diff --git a/examples/hoctahedron1.solid b/examples/hoctahedron1.solid new file mode 100644 index 0000000..88e290f --- /dev/null +++ b/examples/hoctahedron1.solid @@ -0,0 +1,25 @@ +# Hollow Octahedron + +define @ns s - 2 + +-s < x < s +-s < y < s +-s < z < s + +{x + y + (z - s) < 0 ∧ \ +x - y + (z - s) < 0 ∧ \ +-x + y + (z - s) < 0 ∧ \ +-x - y + (z - s) < 0 ∧ \ +x + y - (z + s) < 0 ∧ \ +x - y - (z + s) < 0 ∧ \ +-x + y - (z + s) < 0 ∧ \ +-x - y - (z + s) < 0} \ +⊻ \ +{x + y + (z - @ns) < 0 ∧ \ +x - y + (z - @ns) < 0 ∧ \ +-x + y + (z - @ns) < 0 ∧ \ +-x - y + (z - @ns) < 0 ∧ \ +x + y - (z + @ns) < 0 ∧ \ +x - y - (z + @ns) < 0 ∧ \ +-x + y - (z + @ns) < 0 ∧ \ +-x - y - (z + @ns) < 0} diff --git a/examples/htetra2.solid b/examples/htetra2.solid new file mode 100644 index 0000000..182c8cb --- /dev/null +++ b/examples/htetra2.solid @@ -0,0 +1,107 @@ +# Tetrahedron + +# Tetrahedron bounding box size: + +# Figure 1: Side View +# +# *_ - +# / \ ^ +# / | \_ +# / | \ depth +# / | \_ v +# *----0-------* - +# +# Figure 2: Top View +# +# *_B +# | \_ +# |\ \_ +# | \ \_ +# | \ \_ +# | \A \__ +# | *--__*D +# | / _/ +# | / _/ +# | / _/ +# |/ _/ +# |_/ +# *C + +# From these diagrams, you can tell that the width is the height of an +# equilateral triangle. If we assume the edge of the tetrahedron is s, then: + +define @ns s - 4 + +define @half_height s / 2 +define @nhalf_height @ns / 2 + +# For the depth, a few calculations are necessary: +# +# a + b = s * sin(⅓π) +# a² + (s/2)² = b² +define @a (s/2)*tan(⅙π) +define @na (@ns/2)*tan(⅙π) +define @b s * (sin(⅓π) - tan(⅙π)/2) +define @nb @ns * (sin(⅓π) - tan(⅙π)/2) +# a² + d² = (s*sin(⅓π))² +define @depth s * sqrt((sin(⅓π))^2 - ((1/2)*tan(⅙π))^2) +define @ndepth @ns * sqrt((sin(⅓π))^2 - ((1/2)*tan(⅙π))^2) + +# Considering that the origin is in the center of the base, the min x is -a, +# the min y is -s/2, and the min z is 0 +-@a < x < @b +-@half_height < y < @half_height +0 < z < @depth + +# A can be given by: +# +# (0,0,depth) + +# B and C can be given by: +# +# (-a,±half_height,0) + +# D can be given by: +# +# (b,0,0) + +# The tetrahedron can be given by the intersection of 4 semi-spaces. +# However, one of the semi-spaces is z >= 0, which is implicit in the +# declaration of the z boundaries, so it will not require a condition. + +# Cross Product Cheatsheet +# +# a ⨯ b = | i j k | +# | ax ay az | +# | bx by bz | +# +# = (ay bz - az by, az bx - ax bz, ax by - ay bx) + +# The normal vector for the plane ABC is the cross product of AB and AC +# +# AB = (-a, half_height, -depth) +# AC = (-a, -half_height, -depth) +# +# vABC = (half_height * (-depth) - (-depth) * (-half_height), +# (-depth) * (-a) - (-a) * (-depth), +# (-a) * (-half_height) - half_height * (-a)) = +# (- s * depth, 0, s * a) + +# The normal vector for the plane ADB is the cross product of AD and AB +# +# AD = (b,0,-depth) +# AB = (-a, half_height, -depth) +# +# vABD = (depth * half_height, depth * a + b * depth, b * half_height) + +# The normal vector for the plane ACD is equal to the previous one but +# reflected on the y axis. Thus, we only have to flip a plus to a minus. + +{x * (- s * @depth) + (z - @depth) * (s * @a) ≤ 0 ∧ \ +x * @depth * @half_height + y * @depth * (@a + @b) + (z - @depth) * @b * @half_height ≤ 0 ∧ \ +x * @depth * @half_height - y * @depth * (@a + @b) + (z - @depth) * @b * @half_height ≤ 0} \ +⊻ \ +{x * (- @ns * @ndepth) + (z - @ndepth) * (@ns * @na) ≤ 0 ∧ \ +x * @ndepth * @nhalf_height + y * @ndepth * (@na + @nb) + (z - @ndepth) * @nb * @nhalf_height ≤ 0 ∧ \ +x * @ndepth * @nhalf_height - y * @ndepth * (@na + @nb) + (z - @ndepth) * @nb * @nhalf_height ≤ 0 ∧ \ +z > 1} diff --git a/examples/octahedron1.solid b/examples/octahedron1.solid new file mode 100644 index 0000000..6581e7f --- /dev/null +++ b/examples/octahedron1.solid @@ -0,0 +1,14 @@ +# Octahedron + +-s < x < s +-s < y < s +-s < z < s + +x + y + (z - s) < 0 +x - y + (z - s) < 0 +-x + y + (z - s) < 0 +-x - y + (z - s) < 0 +x + y - (z + s) < 0 +x - y - (z + s) < 0 +-x + y - (z + s) < 0 +-x - y - (z + s) < 0 diff --git a/examples/tetrahedron2.solid b/examples/tetrahedron2.solid new file mode 100644 index 0000000..775af8b --- /dev/null +++ b/examples/tetrahedron2.solid @@ -0,0 +1,97 @@ +# Tetrahedron + +# Tetrahedron bounding box size: + +# Figure 1: Side View +# +# *_ - +# / \ ^ +# / | \_ +# / | \ depth +# / | \_ v +# *----0-------* - +# +# Figure 2: Top View +# +# *_B +# | \_ +# |\ \_ +# | \ \_ +# | \ \_ +# | \A \__ +# | *--__*D +# | / _/ +# | / _/ +# | / _/ +# |/ _/ +# |_/ +# *C + +# From these diagrams, you can tell that the width is the height of an +# equilateral triangle. If we assume the edge of the tetrahedron is s, then: + +define @half_height s / 2 + +# For the depth, a few calculations are necessary: +# +# a + b = s * sin(⅓π) +# a² + (s/2)² = b² +define @a (s/2)*tan(⅙π) +define @b s * (sin(⅓π) - tan(⅙π)/2) +# a² + d² = (s*sin(⅓π))² +define @depth s * sqrt((sin(⅓π))^2 - ((1/2)*tan(⅙π))^2) + +# Considering that the origin is in the center of the base, the min x is -a, +# the min y is -s/2, and the min z is 0 +-@a < x < @b +-@half_height < y < @half_height +0 < z < @depth + +# A can be given by: +# +# (0,0,depth) + +# B and C can be given by: +# +# (-a,±half_height,0) + +# D can be given by: +# +# (b,0,0) + +# The tetrahedron can be given by the intersection of 4 semi-spaces. +# However, one of the semi-spaces is z >= 0, which is implicit in the +# declaration of the z boundaries, so it will not require a condition. + +# Cross Product Cheatsheet +# +# a ⨯ b = | i j k | +# | ax ay az | +# | bx by bz | +# +# = (ay bz - az by, az bx - ax bz, ax by - ay bx) + +# The normal vector for the plane ABC is the cross product of AB and AC +# +# AB = (-a, half_height, -depth) +# AC = (-a, -half_height, -depth) +# +# vABC = (half_height * (-depth) - (-depth) * (-half_height), +# (-depth) * (-a) - (-a) * (-depth), +# (-a) * (-half_height) - half_height * (-a)) = +# (- s * depth, 0, s * a) + +x * (- s * @depth) + (z - @depth) * (s * @a) ≤ 0 + +# The normal vector for the plane ADB is the cross product of AD and AB +# +# AD = (b,0,-depth) +# AB = (-a, half_height, -depth) +# +# vABD = (depth * half_height, depth * a + b * depth, b * half_height) +x * @depth * @half_height + y * @depth * (@a + @b) + (z - @depth) * @b * @half_height ≤ 0 + +# The normal vector for the plane ACD is equal to the previous one but +# reflected on the y axis. Thus, we only have to flip a plus to a minus. +# v +x * @depth * @half_height - y * @depth * (@a + @b) + (z - @depth) * @b * @half_height ≤ 0