裏 RjpWiki

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

算額(その33)

2022年11月22日 | Julia

算額(その33)

岩手県一関市 八幡神社  天保9年(1838) 
http://www.wasan.jp/iwate/itinosekiyahata2.html

円の中に 4 種類の円が収まっている。各円の径を求めよ。

算額の図では中央にある円と上下端にある円は違う色で塗られているが,これは同じ径を持つ円でなければ計算が合わない。

using SymPy
@syms r1::positive, r2::positive, r3::positive, r4::positive, x4::positive;

eq1 = x4^2 + r4^2 - (r3 + r4)^2;
eq2 = x4^2 + (r4 - r1 - r3)^2 - (r1 + r4)^2;
eq3 = r3 + 2r1 + 2r2 - 1;
eq4 = 1 - 2r4 - r3;
eq5 = r2 - r3;

solve([eq1, eq2, eq3, eq4, eq5], (r1, r2, r3, r4, x4))

   1-element Vector{NTuple{5, Sym}}:
    (1/8, 1/4, 1/4, 3/8, 1/2)


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=:top)
   scatter!([x], [y], color=color, markerstrokewidth=0)
   annotate!(x, y, text(string, 10, position, color, vertical))
end;

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r1, r2, r3, r4, x4 = (1/8, 1/4, 1/4, 3/8, 1/2)
   println("r1 = $r1;  r2 = $r2;  r3 = $r3;  r4 = $r4")
   println("x4= $x4")
   plot()
   circle(0, 0, r3, :green)
   circle(0, r1+r3, r1, :blue)
   circle(0, -r1-r3, r1, :blue)
   circle(0, r3 + 2r1 + r2, r2, :red)
   circle(0, -r3 - 2r1 - r2, r2, :red)
   circle(x4, r4, r4, :magenta)
   circle(x4, -r4, r4, :magenta)
   circle(-x4, r4, r4, :magenta)
   circle(-x4, -r4, r4, :magenta)
   if more
       point(0, 0, "0 ", :black, :right)
       point(0, r3, "r3 ", :black, :right)
       point(0, r3+r1, "r3+r1 ", :blue, :right)
       point(0, 1-r2, "1-r2 ", :red, :right)
       point(x4, r4, "(x4,r4)", :magenta, :center)
       vline!([0], color=:black, linewidth=0.25)
       hline!([0], color=:black, linewidth=0.25)
   end
   circle(0, 0, 1, :black)
end;

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

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

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