mathics / Mathics

This repository is for archival. Please see https://github.com/Mathics3/mathics-core
https://mathics.org
Other
2.07k stars 206 forks source link

Add 3d `Arrow` #1457

Closed TiagoCavalcante closed 3 years ago

TiagoCavalcante commented 3 years ago

@rocky could you test the Asymptote 3d arrow for me?

It should (shouldn't but I guess it's going to) draw a two-sided arrow.

e.g.: image

rocky commented 3 years ago

@rocky could you test the Asymptote 3d arrow for me?

It should (shouldn't but I guess it's going to) draw a two-sided arrow.

e.g.: image

Sure but the easiest thing for me to do would be to merge it and the fix on top.

Have you looked at https://tex.stackexchange.com/questions/258052/asymptote-arrow3-only-has-3d-arrow-head to see how to shade the arrowhead?

Also, apparently Asymptote comes with a CLI asy to test drawing images. See https://asymptote.sourceforge.io/

Let me know if you want to make further changes or want me to.

TiagoCavalcante commented 3 years ago

Have you looked at https://tex.stackexchange.com/questions/258052/asymptote-arrow3-only-has-3d-arrow-head to see how to shade the arrowhead?

No, I saw on another site it Arrow3 draws a double-sided arrow (I was wanting a one-sided arrow).

Also, apparently Asymptote comes with a CLI asy to test drawing images. See https://asymptote.sourceforge.io/

Again, thanks.

Let me know if you want to make further changes or want me to.

I was wanting to continue, just didn't know how to test, but you already answered that.

rocky commented 3 years ago

Will continue from here (or not) as desired.

TiagoCavalcante commented 3 years ago

Will continue from here (or not) as desired.

@rocky I didn't understand what you mean.

rocky commented 3 years ago

I had asked before whether you were going to continue with this or not. I guess that question still remains. Are you going to continue with this or not?

Right now I am not seeing this mentioned in CHANGES.rst. In fact I am not seeing any docs or examples. (And as your custom you show output above, but no input for output produced.)

I am not seeing the lighting stuff mentioned on StackOverflow. Please advise.

TiagoCavalcante commented 3 years ago

I had asked before whether you were going to continue with this or not. I guess that question still remains. Are you going to continue with this or not?

Right now I am not seeing this mentioned in CHANGES.rst. In fact I am not seeing any docs or examples. (And as your custom you show output above, but no input for output produced.)

Ok, I'll update CHANGES.rst and the documentation (tomorrow).

I am not seeing the lighting stuff mentioned on StackOverflow. Please advise.

Again, I don't understand: what should be put in StackOverflow?

rocky commented 3 years ago

Have you looked at https://tex.stackexchange.com/questions/258052/asymptote-arrow3-only-has-3d-arrow-head to see how to shade the arrowhead?

From SO:

If I draw a Arrow3, it does not really look 3D-ish because the line is not shaded like a cylinder. How do I change this? Probably drawing the cylinder and arrow head manually together? How?

Just add the currentlight parameter to the draw function as a quick fix. For a more complete explanation of the shading and material options Asymptote provides, see the following questions:

That arrow looks 3D and the example you had does not. I wondered if this is inherent in Asymptote. No it is not. The details though I haven't looked at.

TiagoCavalcante commented 3 years ago

That arrow looks 3D and the example you had does not. I wondered if this is inherent in Asymptote. No it is not. The details though I haven't looked at.

@rocky this shouldn't look 3d: https://reference.wolfram.com/language/ref/Arrow.html#794061. Also, the three.js' arrow doesn't look 3d, a really 3d arrow is much harder to render.

rocky commented 3 years ago

When I just tried that example, here is what I get:

In[1]:= Graphics3D[Arrow[{{1, 1, -1}, {2, 2, 0}, {3, 3, -1}, {4, 4, 0}}]] // TeXForm
Traceback (most recent call last):
  File "/home/rocky/.pyenv/versions/3.7.10/bin/mathics", line 11, in <module>
    load_entry_point('Mathics3', 'console_scripts', 'mathics')()
  File "/src/external-vcs/github/mathics/Mathics/mathics/main.py", line 402, in main
    result = evaluation.evaluate(query, timeout=settings.TIMEOUT)
  File "/src/external-vcs/github/mathics/Mathics/mathics/core/evaluation.py", line 361, in evaluate
    result = run_with_timeout_and_stack(evaluate, timeout, self)
  File "/src/external-vcs/github/mathics/Mathics/mathics/core/evaluation.py", line 118, in run_with_timeout_and_stack
    return request()
  File "/src/external-vcs/github/mathics/Mathics/mathics/core/evaluation.py", line 354, in evaluate
    return self.format_output(self.last_eval, format)
  File "/src/external-vcs/github/mathics/Mathics/mathics/core/evaluation.py", line 447, in format_output
    result = expr.format(self, "System`OutputForm")
  File "mathics/core/expression.py", line 523, in mathics.core.expression.BaseExpression.format
    result = Expression("MakeBoxes", expr, Symbol(form)).evaluate(evaluation)
  File "mathics/core/expression.py", line 1315, in mathics.core.expression.Expression.evaluate
    expr, reevaluate = expr.evaluate_next(evaluation)
  File "mathics/core/expression.py", line 1449, in mathics.core.expression.Expression.evaluate_next
    result = rule.apply(new, evaluation, fully=False)
  File "mathics/core/rules.py", line 67, in mathics.core.rules.BaseRule.apply
    self.pattern.match(yield_match, expression, {}, evaluation, fully=fully)
  File "mathics/core/pattern.py", line 291, in mathics.core.pattern.ExpressionPattern.match
    self.head.match(yield_head, expression.get_head(), vars, evaluation)
  File "mathics/core/pattern.py", line 159, in mathics.core.pattern.AtomPattern.match
    yield_func(vars, None)
  File "mathics/core/pattern.py", line 281, in mathics.core.pattern.ExpressionPattern.match.yield_head
    self.get_pre_choices(
  File "mathics/core/pattern.py", line 429, in mathics.core.pattern.ExpressionPattern.get_pre_choices
    yield_func(vars)
  File "mathics/core/pattern.py", line 258, in mathics.core.pattern.ExpressionPattern.match.yield_choice
    self.match_leaf(
  File "mathics/core/pattern.py", line 655, in mathics.core.pattern.ExpressionPattern.match_leaf
    self.get_wrappings(
  File "mathics/core/pattern.py", line 456, in mathics.core.pattern.ExpressionPattern.get_wrappings
    yield_func(items[0])
  File "mathics/core/pattern.py", line 643, in mathics.core.pattern.ExpressionPattern.match_leaf.yield_wrapping
    leaf.match(
  File "mathics/builtin/patterns.py", line 852, in mathics.builtin.patterns.Pattern_.match
    self.pattern.match(yield_func, expression, new_vars, evaluation)
  File "mathics/builtin/patterns.py", line 1050, in mathics.builtin.patterns.Blank.match
    yield_func(vars, None)
  File "mathics/core/pattern.py", line 623, in mathics.core.pattern.ExpressionPattern.match_leaf.match_yield
    self.match_leaf(
  File "mathics/core/pattern.py", line 655, in mathics.core.pattern.ExpressionPattern.match_leaf
    self.get_wrappings(
  File "mathics/core/pattern.py", line 456, in mathics.core.pattern.ExpressionPattern.get_wrappings
    yield_func(items[0])
  File "mathics/core/pattern.py", line 643, in mathics.core.pattern.ExpressionPattern.match_leaf.yield_wrapping
    leaf.match(
  File "mathics/core/pattern.py", line 159, in mathics.core.pattern.AtomPattern.match
    yield_func(vars, None)
  File "mathics/core/pattern.py", line 640, in mathics.core.pattern.ExpressionPattern.match_leaf.match_yield
    yield_func(new_vars, items_rest)
  File "mathics/core/pattern.py", line 616, in mathics.core.pattern.ExpressionPattern.match_leaf.leaf_yield
    yield_func(
  File "mathics/core/rules.py", line 42, in mathics.core.rules.BaseRule.apply.yield_match
    new_expression = self.do_replace(expression, vars, options, evaluation)
  File "mathics/core/rules.py", line 131, in mathics.core.rules.BuiltinRule.do_replace
    return self.function(evaluation=evaluation, **vars_noctx)
  File "/src/external-vcs/github/mathics/Mathics/mathics/builtin/inout.py", line 2083, in apply_tex
    tex = boxes.boxes_to_tex(evaluation=evaluation)
  File "/src/external-vcs/github/mathics/Mathics/mathics/builtin/box/graphics3d.py", line 426, in boxes_to_tex
    asy = format_fn(elements)
  File "/src/external-vcs/github/mathics/Mathics/mathics/format/asy.py", line 236, in graphics_elements
    result.append(format_fn(element))
  File "/src/external-vcs/github/mathics/Mathics/mathics/format/asy.py", line 156, in arrow3dbox
    ) + ", rgb({1},{2},{3}), Arrow3);".format(*self.edge_color[:3])
TypeError: 'RGBColor' object is not subscriptable

I just opened https://github.com/mathics/Mathics/pull/1460 to address this. Please look that over.

I wonder what's up with how this worked for you and doesn't for me.

BTW, I think I'll add 3D graphics rendering in mathicsscript via asymptote.