裏 RjpWiki

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

算額(その100)

2023年01月18日 | Julia

算額(その100)

東京都杉並区和田 立法寺 天明8年(1788)正月
http://www.wasan.jp/tokyo/ryuhoji.html

直角三角形の中に甲,乙 2 つの円と,正方形が入っている。正方形の一辺の長さと乙円の直径が等しい。

乙円の半径を x として,左右反転させて,下図のように記号を定め,方程式を解く。

using SymPy

function distance(x1, y1, x2, y2, x0, y0)
p1, p2 = sympy.Point(x1, y1), sympy.Point(x2, y2)
l = sympy.Line(p1, p2)
l.distance(sympy.Point(x0, y0))
end;

@syms x::positive, x2::positive, r::positive, x0::positive, y0::positive;
x = 1
eq1 = (x2 - x)^2 + (r - x)^2 - (r + x)^2
eq2 = (2x - x2)^2 + (2x - r)^2 - r^2
eq3 = x0 * (y0 - 4x) - 2x * y0
eq4 = distance(0, y0, x0, 0, x2, r) - r
res = solve([eq1, eq2, eq3, eq4], (r, x2, x0, y0))

   1-element Vector{NTuple{4, Sym}}:
    (25/16, 7/2, 25*sqrt(23)/28 + 173/28, -1676/49 + 400*sqrt(23)/49)

(25/16, 7/2, 25*sqrt(23)/28 + 173/28, -1676/49 + 400*sqrt(23)/49)

   (1.5625, 3.5, 10.460563860100642, 4.945563455614028)

using Plots
using Printf

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

function segment(x1, y1, x2, y2, color=:black; linestyle=:solid, linewidth=0.5)
   plot!([x1, x2], [y1, y2], color=color, linestyle=linestyle, linewidth=linewidth)
end;

function draw(more=false)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   x = 1
   (r , x2, x0, y0) = (25/16, 7/2, 25*sqrt(23)/28 + 173/28, -1676/49 + 400*sqrt(23)/49)
    plot([0, x0, 0, 0], [0, 0, y0, 0], color=:blue, lw=0.5)
    circle(x, x, x, :green)
   plot!([2x, 0, 0, 2x, 2x], [2x, 2x, 4x, 4x, 2x], color=:magenta, lw=0.5)
   circle(x2, r, r)
    if more
       info = @sprintf("x = %.0f, r = %.4f, x2 = %.1f, x0 = %.3f, y0 = %.3f\n", x, r, x2, x0, y0)
       point(1.7, 4.5, info, :black, :left, mark=false)
       point(x2, r, "甲円 (x2,r)", :red, :center)
       point(2x, 2x, "(2x,2x)", :magenta)
       point(x, x, "乙円 (x,x)", :green, :center)
       point(0, y0, " y0", :black, :left, :bottom)
       point(x0, 0, " x0", :black, :left, :bottom)
    end
end;


コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« 算額(その99) | トップ | 算額(その101) »
最新の画像もっと見る

コメントを投稿

Julia」カテゴリの最新記事