Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions mathics/builtin/box/graphics3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PolygonBox,
)
from mathics.builtin.colors.color_directives import Opacity, RGBColor, _ColorObject
from mathics.builtin.drawing.graphics3d import Graphics3D, Style3D
from mathics.builtin.drawing.graphics3d import Coords3D, Graphics3D, Style3D
from mathics.builtin.drawing.graphics_internals import GLOBALS3D
from mathics.core.exceptions import BoxExpressionError
from mathics.core.symbols import Symbol
Expand Down Expand Up @@ -284,11 +284,17 @@ def init(self, graphics, style, item):
self.edge_opacity, self.face_opacity = style.get_style(
Opacity, face_element=True
)
if len(item.elements) != 2:
# Sphere[] and Sphere[positions] stay unevaluated, as in WMA;
# the default center and radius are filled in here.
elements = item.elements
if len(elements) > 2:
raise BoxExpressionError

self.points = expr_to_list_of_3d_points(item.elements[0])
self.radius = item.elements[1].to_python()
if elements:
self.points = expr_to_list_of_3d_points(elements[0])
else:
self.points = (Coords3D(pos=(0, 0, 0)),)
self.radius = elements[1].to_python() if len(elements) == 2 else 1

def extent(self):
result = []
Expand Down
11 changes: 7 additions & 4 deletions mathics/builtin/drawing/graphics3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,16 @@ class Sphere(Builtin):

>> Graphics3D[{Yellow, Sphere[{{-1, 0, 0}, {1, 0, 0}, {0, 0, Sqrt[3.]}}, 1]}]
= -Graphics3D-

'Sphere' is a symbolic representation: it does not evaluate, and the \
default center and radius are only used when it is drawn:
>> {Sphere[], Sphere[{1, 2, 3}]}
= {Sphere[], Sphere[{1, 2, 3}]}
>> Graphics3D[Sphere[{1, 2, 3}]]
= -Graphics3D-
"""

summary_text = "represent a sphere"
rules = {
"Sphere[]": "Sphere[{0, 0, 0}, 1]",
"Sphere[positions_]": "Sphere[positions, 1]",
}


class Tube(Builtin):
Expand Down
10 changes: 10 additions & 0 deletions test/builtin/drawing/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ def test__listplot():
),
"Background 3D",
),
("Sphere[]", None, "Sphere[]", "Sphere is inert"),
("Sphere[{1, 2, 3}]", None, "Sphere[{1, 2, 3}]", "Sphere is inert"),
("f[Sphere[n_]] := n; f[Sphere[7]]", None, "7", "Sphere[n] as a head"),
(
"StringContainsQ[Graphics3D[Sphere[{1, 2, 3}]]//TeXForm//ToString, "
'"sphere((1, 2, 3), 1)"]',
None,
"True",
"default radius when drawn",
),
(
"Graphics3D[Point[Table[{Sin[t], Cos[t], 0}, {t, 0, 2. Pi, Pi / 15.}]]] //Chop//TeXForm//ToString",
None,
Expand Down
Loading