1

I am trying to prepare this exercise in my class on Matlab (as a part of Applied Physics lab for CS engineers) where you have to model the temperature fluctuation over the surface a planet whose one side always faces the parent star and one side is always away from it (half frozen-half baked). Here is the function I am using:

T(Theta, Phi) = T0 + T1*sin^2(Theta) + T2*(1+sin(Phi))

I want to plot the above function on a surface of a sphere as a color plot i.e. the color of a point on the surface should represent the temperature T at the point. How can I go about doing it?

All I have done so far gives me a plot like this: enter image description here

I want something like the image below but with different color distribution of course, given according to the function I gave above.

enter image description here

4
  • What do you mean by "I want to plot the above function on a surface of a sphere"? A sphere is a sphere. Are you saying that you want to map the colours onto a sphere? Or do you want to create a closed 3D object with the above shape, i.e just make the edges on the respective side to meet so to speak? Commented Jan 7, 2015 at 9:08
  • Meaning, the color on the surface of the sphere at a point should represent value of temperature at that point, (Theta, Phi). Commented Jan 7, 2015 at 9:10
  • Something like this, i.sstatic.net/HQXDC.png. With different color distribution of course, given according to the function I gave in the question. Commented Jan 7, 2015 at 9:14
  • in.mathworks.com/matlabcentral/fileexchange/… Commented Jan 7, 2015 at 9:43

1 Answer 1

3

This does it partially:

T0 = 2 ; T1 = 30  ; T2 = 120 ; %// set your boundary conditions here

[X,Y,Z] = sphere(50) ; %// generate coordinates of a sphere
hs = surf(X,Y,Z)     ; %// display the sphere and retrieve the handle to the graphic object
axis equal           ; %// set the axis ratio so the sphere appear as a sphere
shading interp       ; %// small refinement to not see the grid, you can comment that

[azimuth,elevation,r] = cart2sph(X,Y,Z) ;               %// Convert cartesian coordinates to spherical referential
T = T0 + T1*sin(azimuth).^2 + T2.*(1+sin(elevation)) ;  %// Calculate the temperature according to your model
set(hs,'CData',T) ;                                     %// update the sphere graphic object with the new temperature as a collor coding

the sphere

Now you still have to adjust your initial conditions T0, T1 and T3, and may be also add some rotations in case your "hot" and "cold" points are not at the poles.

Sign up to request clarification or add additional context in comments.

3 Comments

You can also do surf(X, Y, Z, T) once you have created T.
@nivag, yes indeed. We could even reduce the number of line further, but seeing how the OP had trouble plotting a spherical shape, I opted to separate the sphere plotting and the temperature data application operations.
Thanks Hoki! It looks exactly like I wanted it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.