Maxima で楕円や回転楕円体を描く

理工系の数学 B の授業で,楕円の周長や面積,回転楕円体の表面積や体積を求めているので。

塗りつぶした楕円

Maxima で長半径 $a$,単半径 $b$ の楕円を描く例。ellipse() を使ってみる。

? ellipse;

-- Graphic object: ellipse (<xc>, <yc>, <a>, <b>, <ang1>, <ang2>)
     Draws ellipses and circles in 2D.

     2D

     'ellipse (<xc>, <yc>, <a>, <b>, <ang1>, <ang2>)' plots an ellipse
     centered at '[<xc>, <yc>]' with horizontal and vertical semi axis
     <a> and <b>, respectively, starting at angle <ang1> with an
     amplitude equal to angle <ang2>.
In [1]:
a: 2$
b: 1$
xlim: a+0.5$
ylim: b+0.5$

draw2d(
  font_size = 14, dimensions=[640, 400],
  /* 縦横比 */
  proportional_axes = xy, 
  /* 表示範囲 */
  xrange = [-xlim, xlim], yrange = [-ylim, ylim],

  /* x 軸 y 軸の表示 */
  xaxis = true, yaxis = true,
  xtics = {["-a", -a], ["a", a]},
  ytics = {["-b", -b], ["b", b]}, 
  user_preamble = "set grid front;",

  transparent = false, fill_color  = yellow,
  line_width = 3,
  color = dark-blue,
  ellipse(0, 0, a, b, 0, 360)
)$

塗りつぶし無しの楕円

In [2]:
a: 2$
b: 1$

draw2d(
  font_size = 14, dimensions=[640, 400],
  /* 縦横比 */
  proportional_axes = xy, 
  /* 表示範囲 */
  xrange = [-xlim, xlim], yrange = [-ylim, ylim],

  /* x 軸 y 軸の表示 */
  xaxis = true, yaxis = true,
  xtics = {["-a", -a], ["a", a]},
  ytics = {["-b", -b], ["b", b]}, 
  user_preamble = "set grid front;",

  transparent = true,
  line_width = 3,
  color = dark-blue,
  ellipse(0, 0, a, b, 0, 360)
)$

長軸の周りに回転した回転楕円体

$\displaystyle y = b \sqrt{1-\frac{x^2}{a^2}} $ を $x$ の周りに回転してできる回転楕円体の表面。

In [3]:
draw2d(
  font_size = 14, dimensions=[640, 400],
  /* 縦横比 */
  proportional_axes = xy, 
  /* 表示範囲 */
  xrange = [-xlim, xlim], yrange = [-ylim, ylim],
  
  /* x 軸 y 軸の表示 */
  xaxis = true, yaxis = true,
  xtics = {["-a", -a], ["a", a]},
  ytics = {["-b", -b], ["b", b]}, user_preamble = "set grid front;",

  transparent = false,
  fill_color  = light-blue,
  line_width = 3,
  color = dark-blue,
  /* 上半分の楕円を描く */
  ellipse(0, 0, a, b, 0, 180), 
  
  color = blue, line_width = 2,
  explicit(0, x, -xlim, xlim)
)$

In [4]:
f(x):= b*sqrt(1-x**2/a**2)$
a: 2$
b: 1$
xlim: a+0.5$
ylim: b+0.5$

draw3d(
  dimensions=[640, 640], proportional_axes = xyz, 
  xrange = [-xlim, xlim],
  yrange = [-xlim, xlim], 
  zrange = [-xlim, xlim], 

  /* 回転体の表面 */
  color = blue, 
  line_width=0.5, xu_grid = 40, yv_grid = 30,
  parametric_surface(x, f(x)*cos(t), f(x)*sin(t), 
                     x, -a, a, t, 0, 2*%pi),

  surface_hide =true, view=[60, 10], 
  axis_3d = false, 

  /* x 軸 */
  color=blue, line_width = 2,
  parametric(x, 0, 0, x, -2.2, 2.2), 

  /* いわゆる「y = y(x)」,実は z = z(x) */
  nticks=100, color=dark-blue, line_width = 3,
  parametric(a*cos(t), 0, b*sin(t), t, 0, %pi)
)$

短軸の周りに回転した回転楕円体

$\displaystyle x = a \sqrt{1-\frac{y^2}{b^2}} $ を $y$ の周りに回転してできる回転楕円体の表面。

In [5]:
draw2d(
  font_size = 14, dimensions=[640, 400],
  /* 縦横比 */
  proportional_axes = xy, 
  /* 表示範囲 */
  xrange = [-xlim, xlim], yrange = [-ylim, ylim],
  
  /* x 軸 y 軸の表示 */
  xaxis = true, yaxis = true,
  xtics = {["-a", -a], ["a", a]},
  ytics = {["-b", -b], ["b", b]}, 
  user_preamble = "set grid front;",

  transparent = false,
  fill_color  = light-pink,
  line_width = 3,
  color = dark-red,
  /* 右半分の楕円を描く */
  ellipse(0, 0, a, b, 90, -180),  
  
  color = red, line_width = 2,
  parametric(0, y, y, -ylim, ylim)
)$

In [6]:
g(z):= a*sqrt(1-z**2/b**2)$

draw3d(
  dimensions=[640, 640], proportional_axes = xyz, 
  xrange = [-a, a],
  yrange = [-a, a], 
  zrange = [-a, a], 
       
  /* 回転体の表面 */
  color = red,
  line_width=0.5, xu_grid = 40, yv_grid = 30,
  parametric_surface(g(z)*cos(t), g(z)*sin(t), z, 
                     z, -b, b, t, 0, 2*%pi),

  surface_hide=true, view=[70, 20], 
  axis_3d = false, 
    
  /* いわゆる「y 軸」,実は z 軸 */
  color=red, line_width = 2,
  parametric(0, 0, z, z, -xlim, xlim), 

  /* いわゆる「x = x(y)」,実は x = x(z) */
  nticks=100, color=dark-red, line_width = 3,
  parametric(a*cos(t), 0, b*sin(t), t, -%pi/2, %pi/2)
)$