2
$\begingroup$

I would like to write a function that draws a graphic object and its projections along the x,y and z axes. I specify the $r,\theta, \phi$ of the object and an arrow and it's dashed projections are created in a Graphics3D list.

However, to draw the lines, it's much easier to work with ${x,y,z}$ coordinates. I am trying to use both of them in my function, but do not know how do this. Here is my function (I apologize for the image, but I cannot control C control V from this linux machine, weird characters appear):

enter image description here

Now I just want to substitute the $x,y,z$ values for the values obtained by the transformation:

{x,y,z} = CoordinateTransform["Spherical" -> "Cartesian", {r, theta, phi}];

Is there any way I can go about this? Also, if there is an easier way for doing this, please let me know. I tried using "Module" as well, but while it did do what I want, it did not allow me to use "Show" to plot it.

Thanks in advance.

$\endgroup$
  • 1
    $\begingroup$ Does this give what you need: Graphics3D[{{Thickness[0.005], RGBColor[.4, .3, .2], Arrow[Tube[{{0, 0, 0}, {x, y, z}}]]}, {Dashed, Line[{{x, y, 0}, {x, y, z}}], Line[{{x, 0, 0}, {x, y, 0}}], Line[{{0, y, 0}, {x, y, 0}}]}}] /. Thread[{x, y, z} -> CoordinateTransform[ "Spherical" -> "Cartesian", {r, θ, ϕ}]]? $\endgroup$ – kglr Apr 29 '16 at 21:04
  • $\begingroup$ It does! Thanks for the help $\endgroup$ – triplebig Apr 29 '16 at 21:09
2
$\begingroup$
spinArrow[r_, θ_, ϕ_] := Module[{cart = CoordinateTransform["Spherical" -> "Cartesian", 
      {r, θ, ϕ}], x, y, z}, {x, y, z} = cart; 
       Graphics3D[{{Thickness[0.005], RGBColor[.4, .3, .2], 
                    Arrow[Tube[{{0, 0, 0}, {x, y, z}}, .005]]}, {Dashed, 
                    Line[{{x, y, 0}, {x, y, z}}], Line[{{x, 0, 0}, {x, y, 0}}], 
                    Line[{{0, y, 0}, {x, y, 0}}]}}, BoxRatios -> 1]]

spinArrow[1, π/4, π/4]

Mathematica graphics

Or use ReplaceAll (/.)

spinArrow2[r_, θ_, ϕ_] := Graphics3D[{{Thickness[0.005], RGBColor[.4, .3, .2], 
                    Arrow[Tube[{{0, 0, 0}, {x, y, z}}]]}, {Dashed, 
                    Line[{{x, y, 0}, {x, y, z}}], Line[{{x, 0, 0}, {x, y, 0}}], 
                    Line[{{0, y, 0}, {x, y, 0}}]}}] /. 
        Thread[{x, y, z} ->  CoordinateTransform["Spherical" -> "Cartesian", {r, θ, ϕ}]]

spinArrow2[1, π/6, π/3]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.