SphericalPlot3D colorfunction discrepancy

General discussion about Mathematica features and functionality...
Forum Rules
By using the Wolfram Faculty Program Forum, you agree not to post any abusive, obscene, vulgar, slanderous, hateful, threatening, or sexually oriented material. Wolfram Faculty Program Forum administrators have the right to remove, edit, move or close any topic at any time should we see fit.

Personal Information: Posts in this forum may be viewed by non-members; however, the forum prohibits non-members from viewing your profile. Although your email address is hidden from both non-members and members, your account is initially configured to allow members to contact you via email through the forum. If you wish to hide your profile, or prohibit others from contacting you directly, you may change these settings by updating your profile through the User Control Panel.

Attachments: Attachments are not currently enabled on this forum. To share a file with others on this site, simply upload your file to the online storage service of your choice and include a link to the file within your post. If your school does not offer an online file storage and sharing service, the following sites provide free basic online file storage and sharing: Mozy, FilesAnywhere, Adrive, and KeepandShare.

SphericalPlot3D colorfunction discrepancy

Postby sjlukacs » Sat Feb 02, 2013 11:30 am

hello one and all,

trying to plot the atomic orbitals in Mathematica. my screen shot is here:

http://web.fscj.edu/Lukacs/images/sphericalplot3D.png

anyway, as you can see the SphericalPlot3D does not represent the colorfunction properly as compared to the ParametricPlot3D. I have copied the code below for reproduction purposes; it should be self contained.

so i am wondering what is the difference? lucas

color[\[CurlyTheta]_, \[CurlyPhi]_, infxn_] :=
RGBColor[(Sign[Re[infxn]] + 1)/2,
0, (-Sign[Re[infxn]] + 1)/2, .75];
1/4 Sqrt[5/Pi] (3 Cos[\[CurlyTheta]]^2 - 1)
SphericalPlot3D[%, {\[CurlyTheta], 0, Pi}, {\[CurlyPhi], 0, 2 Pi},
ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi]},
color[\[CurlyTheta], \[CurlyPhi], %]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]
ParametricPlot3D[
Evaluate[{Cos[\[CurlyPhi]] Sin[\[CurlyTheta]],
Sin[\[CurlyPhi]] Sin[\[CurlyTheta]],
Cos[\[CurlyTheta]]} %%], {\[CurlyTheta], 0, Pi}, {\[CurlyPhi], 0,
2 Pi}, ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi]},
color[\[CurlyTheta], \[CurlyPhi], %%]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]
User avatar
sjlukacs
 
Posts: 3
Joined: Wed Apr 25, 2012 10:08 pm
Organization: FSCJ
Department: chemistry

Re: SphericalPlot3D colorfunction discrepancy

Postby Kathy_Bautista » Wed Feb 06, 2013 4:38 am

Hi Lucas,

I've forwarded your question along to our technical support team so they can opine. I will email you as soon as I hear from them.

-Kathy
Katherine Bautista
Senior Academic Program Manager
Wolfram Research, Inc.
http://www.wolfram.com
User avatar
Kathy_Bautista
Site Admin
 
Posts: 182
Joined: Fri Jul 31, 2009 6:24 pm
Location: Mesa, Arizona
Organization: Wolfram Research, Inc.
Department: Academic Initiatives

Re: SphericalPlot3D colorfunction discrepancy

Postby Michael_Rogers » Sat Feb 16, 2013 9:48 pm

Here's how I thought you were supposed to do it:

Code: Select all
fxn = 1/4 Sqrt[5/Pi] (3 Cos[\[CurlyTheta]]^2 - 1);
SphericalPlot3D[fxn, {\[CurlyTheta], 0, Pi}, {\[CurlyPhi], 0, 2 Pi},
ColorFunction -> Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r}, Evaluate@color[\[CurlyTheta], \[CurlyPhi], fxn]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]


See http://reference.wolfram.com/mathematica/ref/Function.html. Search for Evaluate under "Properties & Relations."

What I'm not sure about is why ParametricPlot3D works. Perhaps it evaluates the color function symbolically and then replaces variables with numbers, whereas SphericalPlot3D feeds numbers directly to the color function.
User avatar
Michael_Rogers
 
Posts: 10
Joined: Mon May 24, 2010 3:28 pm
Organization: Emory University
Department: Oxford College

Re: SphericalPlot3D colorfunction discrepancy

Postby Gerrard_Liddell » Thu Mar 28, 2013 1:53 am

The problem is the function in the option
ColorFunction -> Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate[color[\[CurlyTheta], \[CurlyPhi], fxn]]]

Either put it in by hand

SphericalPlot3D[
1/4 Sqrt[5/\[Pi]] (-1 + 3 Cos[\[CurlyTheta]]^2), {\[CurlyTheta],
0, \[Pi]}, {\[CurlyPhi], 0, 2 \[Pi]},
ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
RGBColor[1/2 (1 + Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0,
1/2 (1 - Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0.75`]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]

Here is a way of getting it into the spherical plot in so it does work correctly:

Clear[fxn];

Hold[SphericalPlot3D[
fxn, {\[CurlyTheta], 0, Pi}, {\[CurlyPhi], 0, 2*Pi},
ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate[color[\[CurlyTheta], \[CurlyPhi], fxn]]],
ColorFunctionScaling -> False,
ImageSize -> 150, Axes -> False, Boxed -> False,
PlotRange -> All]] /.
fxn -> (1/4)*Sqrt[5/Pi]*(3*Cos[\[CurlyTheta]]^2 - 1)


Here is a discussion of some of this:
If you construct the function and insert it via

With[{ fxn = 1/4 Sqrt[5/Pi] (3 Cos[\[CurlyTheta]]^2 - 1)},
Hold@SphericalPlot3D[
fxn, {\[CurlyTheta], 0, Pi}, {\[CurlyPhi], 0, 2 Pi},
ColorFunction ->
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate@color[\[CurlyTheta], \[CurlyPhi], fxn]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]
]

off course it does not work because of scoping replacing the dummy variables:

Hold[SphericalPlot3D[
1/4 Sqrt[5/\[Pi]] (-1 + 3 Cos[\[CurlyTheta]]^2), {\[CurlyTheta],
0, \[Pi]}, {\[CurlyPhi], 0, 2 \[Pi]},
ColorFunction ->
Function[{x$, y$, z$, \[CurlyTheta]$, \[CurlyPhi]$, r$},
Evaluate[
color[\[CurlyTheta]$, \[CurlyPhi]$,
1/4 Sqrt[5/\[Pi]] (-1 + 3 Cos[\[CurlyTheta]]^2)]]],
ColorFunctionScaling -> False, ImageSize -> 150, Axes -> False,
Boxed -> False, PlotRange -> All]]


The function
Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
Evaluate@color[\[CurlyTheta], \[CurlyPhi], fxn]]
does evaluate to:

Function[{x, y, z, \[CurlyTheta], \[CurlyPhi], r},
RGBColor[1/2 (1 + Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0,
1/2 (1 - Sign[-1 + 3 Re[Cos[\[CurlyTheta]]^2]]), 0.75]]

A trace of SphericalPlot reveals that it does correctly evaluate the option to
"ColorFunction" ->
"Function"[{"x", "y", "z", "\[CurlyTheta]", "\[CurlyPhi]", "r"},
"RGBColor"[
"Times"[1/2,
"Plus"[1,
"Sign"["Plus"[-1,
"Times"[3, "Re"["Power"["Cos"["\[CurlyTheta]"], 2]]]]]]], 0,
"Times"[1/2,
"Plus"[1,
"Times"[-1,
"Sign"["Plus"[-1,
"Times"[3, "Re"["Power"["Cos"["\[CurlyTheta]"], 2]]]]]]]],
0.75]]
(the strings are to allow analysis of the trace)

Hope this helps
Gerrard
User avatar
Gerrard_Liddell
 
Posts: 2
Joined: Fri Mar 12, 2010 7:55 am
Organization: University of Otago
Department: Mathematics


Return to General Mathematica Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron