Skip to content

Commit

Permalink
Add Octahedron
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Feb 2, 2025
1 parent 8c10f5a commit c401a9a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
45 changes: 44 additions & 1 deletion mathics/format/asy_polyhedra.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def dodecahedron(center: tuple, length: float, color_str: str) -> str:
real a=sqrt(1-phi*phi/4-g*g)+phi/2;
triple center={center};
real length={length};
real length={length} / 2;
triple[] d;
d[0]=center + length*(phi/2,phi/2,phi/2);
d[1]=center + length*(-phi/2,phi/2,phi/2);
Expand Down Expand Up @@ -73,6 +73,48 @@ def dodecahedron(center: tuple, length: float, color_str: str) -> str:
"""


def octahedron(center: tuple, length: float, color_str: str) -> str:
"""
Return an asymptote program string to draw a tetrahedron at `center`
with length `length`.
"""
return f"""
triple center={center};
real vertex_position = 0.30615 * {length};
triple[] d;
path3[] p;
d[0]=center + (0, vertex_position, 0);
d[1]=center + (0, 0, vertex_position);
d[2]=center + (-vertex_position, 0, 0);
d[3]=center + (0, 0, -vertex_position);
d[4]=center + (vertex_position, 0, 0);
d[5]=center + (0, -vertex_position, 0);
p[0]=d[0]--d[1]--d[2]--cycle;
p[1]=d[0]--d[2]--d[3]--cycle;
p[2]=d[0]--d[3]--d[4]--cycle;
p[3]=d[0]--d[4]--d[1]--cycle;
p[4]=d[5]--d[1]--d[2]--cycle;
p[5]=d[5]--d[2]--d[3]--cycle;
p[6]=d[5]--d[3]--d[4]--cycle;
p[7]=d[5]--d[4]--d[1]--cycle;
pen sides={color_str};
draw(surface(p[0]),sides);
draw(surface(p[1]),sides);
draw(surface(p[2]),sides);
draw(surface(p[3]),sides);
draw(surface(p[4]),sides);
draw(surface(p[5]),sides);
draw(surface(p[6]),sides);
draw(surface(p[7]),sides);
"""


def tetrahedron(center: tuple, length: float, color_str: str) -> str:
"""
Return an asymptote program string to draw a tetrahedron at `center`
Expand Down Expand Up @@ -109,5 +151,6 @@ def unimplimented_polygon(center: tuple, length: float, color_str: str) -> str:

HEDRON_NAME_MAP: Dict[str, Callable] = {
"dodecahedron": dodecahedron,
"octahedron": octahedron,
"tetrahedron": tetrahedron,
}
3 changes: 2 additions & 1 deletion mathics/format/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ def graphics3dbox(self, elements=None, **options) -> str:
import tube;
size({0}cm, {1}cm);
currentprojection=perspective({2[0]},{2[1]},{2[2]});
currentlight=light(rgb(0.5,0.5,1), {5}specular=red, (2,0,2), (2,2,2), (0,2,2));
currentlight=light(0,5,10);
//currentlight=light(rgb(0.5,0.5,0.5), {5}specular=red, (2,0,2), (2,2,2), (0,2,2));
{3}
{4}
\end{{asy}}
Expand Down
4 changes: 2 additions & 2 deletions test/builtin/drawing/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"import tube;\n"
"size(6.6667cm, 6.6667cm);\n"
"currentprojection=perspective(2.6,-4.8,4.0);\n"
"currentlight=light(rgb(0.5,0.5,1), background=rgb(1, 0.1, 0.1), specular=red, (2,0,2), (2,2,2), (0,2,2));\n"
"currentlight=light(rgb(0.5,0.5,0.5), background=rgb(1, 0.1, 0.1), specular=red, (2,0,2), (2,2,2), (0,2,2));\n"
"// Sphere3DBox\n"
"draw(surface(sphere((0, 0, 0), 1)), rgb(1,1,1)+opacity(1));\n"
"draw(((-1,-1,-1)--(1,-1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1));\n"
Expand Down Expand Up @@ -133,7 +133,7 @@
"import tube;\n"
"size(6.6667cm, 6.6667cm);\n"
"currentprojection=perspective(2.6,-4.8,4.0);\n"
"currentlight=light(rgb(0.5,0.5,1), specular=red, (2,0,2), (2,2,2), (0,2,2));\n"
"currentlight=light(rgb(0.5,0.5,0.5), specular=red, (2,0,2), (2,2,2), (0,2,2));\n"
"// Point3DBox\npath3 g=(0,1,0)--(0.20791,0.97815,0)--(0.40674,0.91355,0)--"
"(0.58779,0.80902,0)--(0.74314,0.66913,0)--(0.86603,0.5,0)--(0.95106,0.30902,0)--"
"(0.99452,0.10453,0)--(0.99452,-0.10453,0)--(0.95106,-0.30902,0)--(0.86603,-0.5,0)"
Expand Down

0 comments on commit c401a9a

Please sign in to comment.