Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I graph:

  If[11*Cos[t] <= 5, 
    {9*Cos[s]*Sin[t], 10*Sin[s]*Sin[t], 
    11*Cos[t]}, Null], 
{s, 0, 2*Pi}, {t, 0, Pi}]

I get

but I want to get:

enter image description here

Why does my code generate those spike and etches on top of the partially cut ellipsoid, instead of giving a smooth top like the second picture?

share|improve this question
Hi "user9197"! I edited your question a bit - if you want to see how, click on the "edit/edited" links above. – cormullion Aug 23 '13 at 16:48
Thank You, I wasn't able to add pictures since I did not have enough reputation. – user9197 Aug 23 '13 at 16:52
How did you get 2nd graph? – Vitaliy Kaurov Aug 23 '13 at 16:53
I used ContourPlot3D, but I want to make the graph using a parametric setting. – user9197 Aug 23 '13 at 16:54

Better solution

Actually, you don't need a different parametrization as I suggest below. I haven't really looked at your formula before which I should have done. The probably best solution is to transform your condition into explicit values for t like this:

Reduce[11*Cos[t] <= 5 && 0 <= t <= Pi, t]

(* ArcCos[5/11] <= t <= Pi *)

And now you remove your if condition and adjust your time interval

ParametricPlot3D[{9*Cos[s]*Sin[t], 10*Sin[s]*Sin[t], 11*Cos[t]}, 
 {s, 0, 2*Pi}, {t, ArcCos[5/11], Pi}]

That's far easier.

Quick Hack

ParametricPlot3D expects 3d point for all input values of s and t. What you do by returning Null is kind of rude and most likely confuses the algorithm which tries to construct a polygon surface.

I would really recommend that you transform your expression into a better parameterization, but for a quick hack it seems sufficient to not return Null but the point on the ring at z=5.

expr = {9*Cos[s]*Sin[t], 10*Sin[s]*Sin[t], 11*Cos[t]}; 
sol = Last@Solve[11*Cos[t] == 5, t];
With[{surf = expr, ring = expr /. sol},
  If[11*Cos[t] <= 5, surf, ring], {s, 0, 2*Pi}, {t, 0, Pi}]

Mathematica graphics

share|improve this answer
THANKS. Can you please recommend how transform this into a better parametrization. – user9197 Aug 23 '13 at 17:31
@user9197 Please see my update. Sorry, you parametrization is fine, but what you can do is, you can calculate explicit settings for your time interval which fulfill the if if condition you are using. – halirutan Aug 23 '13 at 17:46

You can also do this with RegionFunction:

ParametricPlot3D[{9*Cos[s]*Sin[t], 10*Sin[s]*Sin[t], 11*Cos[t]}, 
 {s, 0, 2*Pi}, {t, 0, Pi}, RegionFunction -> (11 Cos[#5] <= 5 &)]

enter image description here

share|improve this answer
What does #5 mean. – user9197 Sep 14 '13 at 22:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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