1
$\begingroup$

Basically, I don't know whether I am missing something mathematically fundamental or I misued Mathematica's functions.

(*Roll,Pitch,Yawn*)
Rx = {{1, 0, 0}, {0, Cos[gamma], -Sin[gamma]}, {0, Sin[gamma], 
    Cos[gamma]}};
Ry = {{Cos[beta], 0, Sin[beta]}, {0, 1, 0}, {-Sin[beta], 0, 
    Cos[beta]}};
Rz = {{Cos[alpha], -Sin[alpha], 0}, {Sin[alpha], Cos[alpha], 0}, {0, 
    0, 1}};
R[alpha_, beta_, gamma_] = Rx.Ry.Rz;

OffsetTrans[d_, e_, f_] := {d, e, f};(*translation*)

X0[x0_, y0_, z0_] := {x0, y0, z0};
XPar[theta_, phi_, a_, b_, c_, alpha_, beta_, gamma_] = 
  R[alpha, beta, gamma].X0[x0, y0, z0] /. {x0 -> 
     a Cos[theta] Sin[phi], y0 -> b Sin[theta] Sin[phi], 
    z0 -> c Cos[phi]};
XParTrans[theta_, phi_, d_, e_, f_, a_, b_, c_, alpha_, beta_, 
  gamma_] = 
 OffsetTrans[d, e, f] + 
  XPar[theta, phi, a, b, c, alpha, beta, 
   gamma];(*parametric equations of arbitrary oriented and translated \
ellipsoid*)

ParametricPlot3D[
 XParTrans[theta, phi, 0, 0, 0, 7, 5, 3, Pi/3, Pi/3, Pi/3], {theta, 0,
   2 Pi}, {phi, 0, Pi}, 
 PlotStyle -> Directive[Orange, Specularity[White, 40], Opacity[0.5]],
  Mesh -> None]

enter image description here

(*Cartesian equation*)
X = {x, y, z};(*vector containing the three coordinate
axes*)
U = {Δx, Δy, Δz};(*a \
vector containing the distances that the center
of the ellipsoid is removed from the coordinate system origin {0,0,0}*)
\
V = {{1/a^2, 0, 0}, {0, 1/b^2, 0}, {0, 0, 1/
   c^2}};(*a shape matrix containing the semi-axes a,b,and c*)

RotatedEllipsoid[x_, y_, 
  z_, Δx_, Δy_, Δz_, a_, b_,
   c_, alpha_, beta_, 
  gamma_] = (X - U).R[alpha, beta, gamma].V.Transpose[
   R[alpha, beta, gamma]].(X - U);

ContourPlot3D[
 RotatedEllipsoid[x, y, z, 0, 0, 0, 7, 5, 3, Pi/3, Pi/3, Pi/3] == 
  1, {x, -7, 7}, {y, -5, 5}, {z, -3, 3}, 
 ContourStyle -> 
  Directive[Orange, Specularity[White, 40], Opacity[0.5]], 
 Mesh -> None]

enter image description here

Why the outputs are not the same?
Thanks.

$\endgroup$
3
  • $\begingroup$ @Jason B. Thanks for the editing. How, can insert greek characters when I make a post? $\endgroup$
    – Dimitris
    Commented Dec 2, 2015 at 15:11
  • $\begingroup$ Try PlotRange->All $\endgroup$ Commented Dec 2, 2015 at 15:16
  • $\begingroup$ dimitris, you have @halirutan to thank for that. github.com/halirutan/SE-Editor-Buttons $\endgroup$
    – Jason B.
    Commented Dec 2, 2015 at 15:19

1 Answer 1

3
$\begingroup$

You need to make sure that you have the same plotting range in the two different plots. Since ParametricPlot3D automatically chooses the plotting range for you, you can just grab the plotrange from the parametric plot.

plot1 = ParametricPlot3D[
   XParTrans[theta, phi, 0, 0, 0, 7, 5, 3, Pi/3, Pi/3, Pi/3], {theta, 
    0, 2 Pi}, {phi, 0, Pi}, 
   PlotStyle -> 
    Directive[Orange, Specularity[White, 40], Opacity[0.5]], 
   Mesh -> None, BoxRatios -> {1, 1, 1}, ImageSize -> 400, 
   PlotPoints -> 50];

(* Get the plot range from the undocumented hidden function *)

prange = Charting`get3DPlotRange@plot1;

(* Extend the x,y, and z range just a little bit when feeding them as   the {x,xmin,xmax} values *)

drange = Flatten /@ Transpose[{{x, y, z}, 1.1 prange}];


plot2 = ContourPlot3D[
   RotatedEllipsoid[x, y, z, 0, 0, 0, 7, 5, 3, Pi/3, Pi/3, Pi/3] == 1,
    Evaluate@drange[[1]], Evaluate@drange[[2]], Evaluate@drange[[3]], 
   ContourStyle -> 
    Directive[Orange, Specularity[White, 40], Opacity[0.5]], 
   Mesh -> None, PlotRange -> prange, BoxRatios -> {1, 1, 1}, 
   PlotPoints -> 50, ImageSize -> 400];

Grid[{{plot1, plot2}}]

enter image description here

$\endgroup$

Your Answer

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

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