Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The procedure ContourPlot3D allows plotting the contour lines of the components of a 3D-vector. The problem is I don't know how to give the contour planes of each individual component its own colour. To be more specific: green for the X-component, yellow for the Y and red for the Z-component contour planes.

Clear["Global'*"];
B[x_, y_, z_, a_, b_, c_, Br_] :=
  (e := {0, 0, 0};
   Sum[s = x - a (-1)^i; 
    Sum[t = y - b (-1)^j; 
     Sum[u = z - c (-1)^k; r = Sqrt[s^2 + t^2 + u^2]; 
      e = e + (-1)^(i + j + k) {Log[r - t], Log[r - s], 
          ArcTan[(s t)/(r u)]};
      , {k, 0, 1}], {j, 0, 1}]  , {i, 0, 1}];
   Return[e Br/(4 Pi)]);
a = 0.0456/2; b = a; c := 0.0175; Br := 1.4;

ContourPlot3D[
 B[x, y, z, a, b, c, Br], {x, -2 a, 2 a}, {y, -2 a, 2 a}, {z, 0, 4 c},
  Contours -> 21, PlotLabel -> "Field cuboidal magnet", 
 RegionFunction -> (! (#1 > 0 && #2 < 0 && #3 > 0) && ! (#1^2 < 
         a^2 && #2^2 < b^2 && #3^2 < c^2) &), 
 ContourStyle -> 
  Table[Directive[Opacity[0.3], ColorData["BrightBands"][f], 
    Specularity[White, 60]], {f, -0.5, 0.5, 0.05}], PlotPoints -> 16, 
 MaxRecursion -> 0, Mesh -> False] 

Mathematica graphics

share|improve this question
1  
Hi! and welcome to Mma.SE. You can format code with the {} button above the edit window. Folks will appreciate it, if you do. Thanks. –  Michael E2 Nov 30 '13 at 17:14
add comment

1 Answer

Thanks to Kuba's comment, I realize that the plot was not doing what I thought it was. Here is a fixed version. Plot each component and combine them. It might seem inefficient, but it's over 15 times faster.

Show@MapThread[
  ContourPlot3D[#1,
    {x, -2 a, 2 a}, {y, -2 a, 2 a}, {z, 0, 4 c},
    Contours -> 21, PlotLabel -> "Field cuboidal magnet", 
    RegionFunction -> (! (#1 > 0 && #2 < 0 && #3 > 0) && ! (#1^2 < 
            a^2 && #2^2 < b^2 && #3^2 < c^2) &), 
    ContourStyle -> 
     Directive[Opacity[0.5], #2, Specularity[White, 60]],
    PlotPoints -> 16, MaxRecursion -> 0, Mesh -> False, 
    Lighting -> "Neutral"] &,
  {B[x, y, z, a, b, c, Br], {Green, Yellow, Red}}]

Mathematica graphics

share|improve this answer
    
It might be that the OP want's also to scale each like he did in the example. I've thought that something like Table[Blend[{color, White}, int], {color, {Green, Yellow, Red}}, {int, 0, 1, 1/20}] will work but it seems it does not. –  Kuba Nov 30 '13 at 18:34
    
@Kuba Possibly, but the image is rather overcrowded with information as it is. Thanks for the comment. It made realize I made a mistake. :) –  Michael E2 Nov 30 '13 at 19:11
    
Thanks, It is exactly what I had in mind. Yes, overcrowded, but I think it will set a new line in presenting the results of solving Maxwell equations in lectures and books. Visualise the field is what engineers need. –  John Compter Dec 1 '13 at 9:10
add comment

Your Answer

 
discard

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.