裏 RjpWiki

Julia ときどき R, Python によるコンピュータプログラム,コンピュータ・サイエンス,統計学

算額(その12)

2022年11月06日 | Julia

算額(その12)

山形県山形市山寺 立石寺(山寺)根本中堂 大正3年
http://www.wasan.jp/yamagata/yamadera.html

下図のように,正方形の中に四分円,大小の円がある。円の半径を求めよ。


これも,ちょっと面倒であるが紙と鉛筆で計算できる。

正方形の一辺の長さを 1,大円,小円の半径と中心座標を r1, (r1, y1), r2, (x2, y2) とする。

using SymPy
@syms r1::positive, r2::positive, y1::positive, x2::positive, y2::positive
eq1 = r1^2 + y1^2 - (1 - r1)^2;
eq2 = (1//2)^2 + (1 - r2)^2 - (1 + r2)^2;
eq3 = (1 - r1)^2 + y1^2 - (1 + r1)^2;

solve([eq1, eq2, eq3], (r1, r2, y1))

   1-element Vector{Tuple{Sym, Sym, Sym}}:
    (1/6, 1/16, sqrt(6)/3)

using Plots

function circle(ox, oy, r, color=:red; beginangle=0, endangle=360)
   θ = beginangle:0.1:endangle
   x = r.*cosd.(θ)
   y = r.*sind.(θ)
   plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
end;

function point(x, y, string="", color=:green, position=:left, vertical=:center)
   scatter!([x], [y], color=color, markerstrokewidth=0)
   annotate!(x, y, text(string, 10, position, color))
end;

function draw(more=false)
   pyplot(size=(500, 500), aspectratio=1, label="", fontfamily="IPAMincho")
   (r1, r2, y1) = (1//6, 1//16, sqrt(6)/3)
   println("r1 = $r1,  r2 = $r2,  y1 = $y1")
   plot()
   if more
       point(r1, y1, " (r1, y1)", :blue)
       point(1/2, 1 - r2, " (1/2, 1 - r2)", :blue)
   end

   circle(1, 0, 1, beginangle=90, endangle=180)
   plot!([0, 1, 1, 0, 0], [0, 0, 1, 1, 0], color=:red, linewidth=0.5,
       xlims=(-0.05, 1.05), ylims=(-0.05, 1.05))
   circle(r1, y1, r1, :blue)
   circle(1/2, 1 - r2, r2, :blue)
   circle(0, 0, 1, beginangle=0, endangle=90)
end;

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

算額(その11)

2022年11月06日 | Julia

算額(その11)

山形県山形市山寺 立石寺(山寺)根本中堂 大正3年(1914)4月
http://www.wasan.jp/yamagata/yamadera.html

東京都住吉神社 嘉永8年(1851)
http://www.wasan.jp/tokyo/sumiyosi.html



下図のように,半円の中に 3 つの円がある。円の半径を求めよ。

これは簡単。中学生でも暗算で解答できるだろう。

using SymPy
@syms x::positive, y::positive, r::positive
eq1 = x^2 + r^2 - (1-r)^2;
eq2 = x^2 +(1 - 2r)^2 - 4r^2;

solve([eq1, eq2], (x, r))

   1-element Vector{Tuple{Sym, Sym}}:
    (sqrt(3)/3, 1/3)

using Plots

function circle(ox, oy, r, color=:red)
   θ = 0:0.01:2pi
   x = r.*cos.(θ)
   y = r.*sin.(θ)
   plot!(ox .+ x, oy .+ y, color=color)
end;

function point(x, y, string="", color=:green, position=:left, vertical=:center)
   scatter!([x], [y], color=color, markerstrokewidth=0)
   annotate!(x, y, text(string, 10, position, color))
end;

function draw(more=false)
   pyplot(size=(500, 500), aspectratio=1, label="", fontfamily="IPAMincho")
   x, r = (sqrt(3)/3, 1/3)
   println("$x, $r")
   plot()
   if more
       point(x, r, " (x, r)", :blue)
       point(-x, r, " (-x, r)", :blue)
       point(0, 1 - r, " (0, 1-r)", :blue)
   end

   circle(0, 1 - r, r, :blue)
   circle(x, r, r, :blue)
   circle(-x, r, r, :blue)
   for i = 0:60:180
       plot!([0, cosd(i)], [0, sind(i)], color=:black)
   end
   circle(0, 0, 1, :black)
end;

 

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PVアクセスランキング にほんブログ村

PVアクセスランキング にほんブログ村