裏 RjpWiki

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

算額(その127)

2023年02月10日 | Julia

算額(その127)

群馬県桐生市天神町 桐生天満宮 明治11年(1878)4月
http://www.wasan.jp/gunma/kiryutenmangu1.html

外円の中に 甲,乙,丙,丁,戊の円が入っている。乙円,丙円,戊円の径が 15寸,6寸,4寸であるとき,甲円,丁円,外円の径を求めよ。

復元奉納された算額は,もともとなのかもしれないが,正確な比率に基づくものではない。正解を書いているので,図の比率がおかしいのはすぐに分かるのではあるが。
http://www.wasan.jp/gunma/tenmangukaisetu.png

それにしても,方程式が 12 本というのは,今の所最多記録である。変数は 13 個であるが,どれか一つの円(丁円にした)の中心座標が 0 になるように回転するとすれば変数は 12 個になり無事方程式を解くことができる。

算額(その723)で解き直した。
https://blog.goo.ne.jp/r-de-r/e/4a0d1938c82c456123641ba6c54462d1

甲円の中心座標,半径 x1, y1, r1
丁円の中心座標,半径 0, y2, r2
乙円の中心座標    x3, y3
丙円の中心座標    x4, y4
戊円の中心座標    x5, y5
外円の半径          r0

using SymPy

@syms x1, y1, r1, x2, y2, r2, x3, y3, x4, y4, x5, y5, r0;
x2 = 0
eq1 = (x1 - x3)^2 + (y1 - y3)^2 - (r1 + 15)^2 # 甲乙
eq2 = (x1 - x4)^2 + (y1 - y4)^2 - (r1 +6)^2 # 甲丙
eq3 = (x1 - x5)^2 + (y1 - y5)^2 - (r1 + 4)^2 # 甲戊
eq4 = x1^2 + y1^2 - (r0 - r1)^2 # 甲外
eq5 = (x2 - x3)^2 + (y2 - y3)^2 - (r2 + 15)^2 # 乙丁
eq6 = (x3 - x5)^2 + (y3 - y5)^2 - (4 + 15)^2 # 乙戊
eq7 = x3^2 + y3^2 - (r0 - 15)^2 # 乙外
eq8 = (x4 - x5)^2 + (y4 - y5)^2 - (4 + 6)^2 # 丙戊
eq9 = x4^2 + y4^2 - (r0 - 6)^2 # 丙外
eq10 = (x2 - x4)^2 + (y2 - y4)^2 - (r2 + 6)^2 # 丁丙
eq11 = (x2 - x5)^2 + (y2 - y5)^2 - (r2 + 4)^2 # 丁戊
eq12 = x2^2 + y2^2 - (r0 - r2)^2; # 丁外

しかし例のごとく,nlsolve() でなくては解けない。また,初期値の設定に敏感なので手こずる。

# res = solve([eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10, eq11, eq12])

println(eq1, ",")
println(eq2, ",")
println(eq3, ",")
println(eq4, ",")
println(eq5, ",")
println(eq6, ",")
println(eq7, ",")
println(eq8, ",")
println(eq9, ",")
println(eq10, ",")
println(eq11, ",")
println(eq12, ",")


   -(r1 + 15)^2 + (x1 - x3)^2 + (y1 - y3)^2,
   -(r1 + 6)^2 + (x1 - x4)^2 + (y1 - y4)^2,
   -(r1 + 4)^2 + (x1 - x5)^2 + (y1 - y5)^2,
   x1^2 + y1^2 - (r0 - r1)^2,
   x3^2 - (r2 + 15)^2 + (y2 - y3)^2,
   (x3 - x5)^2 + (y3 - y5)^2 - 361,
   x3^2 + y3^2 - (r0 - 15)^2,
   (x4 - x5)^2 + (y4 - y5)^2 - 100,
   x4^2 + y4^2 - (r0 - 6)^2,
   x4^2 - (r2 + 6)^2 + (y2 - y4)^2,
   x5^2 - (r2 + 4)^2 + (y2 - y5)^2,
   y2^2 - (r0 - r2)^2,

using NLsolve

function nls(func, params...; ini = [0.0])
if typeof(ini) <: Number
r = nlsolve((vout, vin) -> vout[1] = func(vin[1], params..., [ini]))#, ftol=1e-14)
v = r.zero[1]
else
r = nlsolve((vout, vin)->vout .= func(vin, params...), ini)#, ftol=1e-14)
v = r.zero
end
return v, r.f_converged
end;

function H(u)
 (x1, y1, r1, y2, r2, x3, y3, x4, y4, x5, y5, r0) = u
 return [
-(r1 + 15)^2 + (x1 - x3)^2 + (y1 - y3)^2,
-(r1 + 6)^2 + (x1 - x4)^2 + (y1 - y4)^2,
-(r1 + 4)^2 + (x1 - x5)^2 + (y1 - y5)^2,
x1^2 + y1^2 - (r0 - r1)^2,
x3^2 - (r2 + 15)^2 + (y2 - y3)^2,
(x3 - x5)^2 + (y3 - y5)^2 - 361,
x3^2 + y3^2 - (r0 - 15)^2,
(x4 - x5)^2 + (y4 - y5)^2 - 100,
x4^2 + y4^2 - (r0 - 6)^2,
x4^2 - (r2 + 6)^2 + (y2 - y4)^2,
x5^2 - (r2 + 4)^2 + (y2 - y5)^2,
y2^2 - (r0 - r2)^2,
   ]
end;

iniv = [-28.0, 26, 36, # x1, y1, r1 甲
   67, 5, # y2, r2 丁
   19, 51, # x3, y3 乙
   -12, 64, # x4, y4 丙
   -3, 57, # x5, y5 戊
   63] .* (60/66)

res = nls(H, ini=iniv)
println(res)

   ([-23.141676475196107, 19.090909090909108, 30.00000000000001, 55.00000000000003, 5.000000000000002, 15.4277843167974, 42.2727272727273, -10.799449021758182, 52.909090909090935, -3.085556863359481, 46.54545454545457, 60.00000000000003], true)

外円の径 = 60.000,  甲円の径 = 30.000,  丁円の径 5.000 である。

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 circle(ox, oy, r, color=:red; beginangle=0, endangle=360, fill=false)
 θ = beginangle:0.1:endangle
 x = r.*cosd.(θ)
 y = r.*sind.(θ)
  if fill
      plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5, seriestype=:shape, fillcolor=color)
  else
      plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
  end
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)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (x1, y1, r1, y2, r2, x3, y3, x4, y4, x5, y5, r0) = res[1]
   @printf("外円の径 = %.3f,  甲円の径 = %.3f,  丁円の径 %.3f\n", r0, r1, r2)
   x2 = 0
   plot()
   circle(0, 0, r0)
   circle(x1, y1, r1, :green)
   circle(x2, y2, r2, :brown)
   circle(x3, y3, 15, :blue)
   circle(x4, y4, 6, :magenta)
   circle(x5, y5, 4)
   if more == true
       point(x1, y1, "甲", :green)
       point(x2, y2, "丁", :brown)
       point(x3, y3, "乙", :blue)
       point(x4, y4, "丙", :magenta)
       point(x5, y5, "戊", :red)
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
   else
       plot!(showaxis=false)
   end
end;

 

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

算額(その126)

2023年02月10日 | Julia

算額(その126)

群馬県吾妻郡東吾妻町 一宮神社 明治5年(1872)3月
http://www.wasan.jp/gunma/itinomiya.html

正方形の中に 5 個の円が入っている。円の半径を求めよ。

算額(その29)https://blog.goo.ne.jp/r-de-r/e/a9e1b842cd8d371848fd4f8e8233c438 に似ているが違う。

図のように記号を定め方程式を解く。

using SymPy

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

res = solve([eq1, eq2], (r, y))

   4-element Vector{Tuple{Sym, Sym}}:
    (6/13 - (14 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2)^3/364 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/364 + 16*(14 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2)^2/91 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/364, 14 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2)
    (6/13 - (14 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2)^3/364 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/364 + 16*(14 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2)^2/91 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/364, 14 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) + 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2 + sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2)
    (6/13 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/364 + 16*(14 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2)^2/91 - (14 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2)^3/364 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/364, 14 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2 - sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2)
    (6/13 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/364 + 16*(14 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2)^2/91 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/364 - (14 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2)^3/364, 14 - sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3))/2 + sqrt(4576/3 - 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3) - 41696/sqrt(2288/3 + 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) + 2*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)) - 17816/(9*(142624/27 + 728*sqrt(143931)*I/9)^(1/3)))/2)

for i = 1:4
   println(res[i][1].evalf(), " ", res[i][2].evalf())
end

   1.23852234934513 + 2.40071286340101e-30*I 2.22701157420417 + 4.36922704976021e-28*I
   73.4676488890155 + 2.40037272088137e-30*I 55.3541864820079 + 4.36922704975308e-28*I
   0.905402947574918 - 2.40064155422471e-30*I -1.71373626518588 - 4.3692270498592e-28*I
   0.388425814064434 - 2.40067662309469e-30*I 0.13253820897379 - 4.36922704965409e-28*I

いずれも複素数表示になっているが,虚部はほとんど 0 なので,実数としてよい。この内の 4 番目の解が妥当である。

すなわち,円の半径は 0.388425814064434, y = 0.13253820897379 である。

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 circle(ox, oy, r, color=:red; beginangle=0, endangle=360, fill=false)
 θ = beginangle:0.1:endangle
 x = r.*cosd.(θ)
 y = r.*sind.(θ)
  if fill
      plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5, seriestype=:shape, fillcolor=color)
  else
      plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
  end
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)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (r, y) = 0.388425814064434, 0.132538208973790
   @printf("r = %.3f, y = %.3ff\n", r, y)
   plot([1, 1, -1, -1, 1], [-1, 1, 1, -1, -1], color=:black, lw=0.5)
   circle(0, 1 - r, r, :black)
   circle(1 - r, y, r)
   circle(r - 1, y, r)
   circle(r, r - 1, r)
   circle(-r, r - 1, r)
   if more == true
       point(0, 1 - r, "1-r ", :red, :right)
       point(1 - r, y, "(1-r,y)", :red, :center)
       point(r, r - 1, "(r,r-1)", :red, :center)
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
   else
       plot!(showaxis=false)
   end
end;

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

算額(その125)

2023年02月10日 | Julia

算額(その125)

群馬県前橋市 総社神社 安政5年(1858)
http://www.wasan.jp/gunma/sojabig.html

外円の中に 4 種類の円が入っている。それぞれの半径を求めよ。

外円の半径を 1,甲円,乙円,丙円,丁円,の半径をそれぞれ r1, r2, r3, r4,丙円,丁円の中心の x 座標を x3, x4 として,方程式を解く。

using SymPy

@syms r1::positive, r2::positive, r3::positive, r4::positive, x3::positive, x4::positive;
eq1 = 2r1 + r2 - 1  # 外円の半径が 1
eq2 = x3^2 + (1 - r1 - r3)^2 - (r1 + r3)^2  # 甲円,丙円が外接する
eq3 = x4^2 + (1 - r1 - r4)^2 - (r1 + r4)^2  # 甲円,丁円が外接する
eq4 = x4^2 + r4^2 - (r2 + r4)^2  # 乙円,丁円が外接する
eq5 = (x3 - x4)^2 + (r3 - r4)^2 - (r3 + r4)^2  # 丙円,丁円が外接する
eq6 = x3^2 + r3^2 - (1 -r3)^2;  # 丙円が外円に内接する

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

   1-element Vector{NTuple{6, Sym}}:
    (-1 + sqrt(2), 3 - 2*sqrt(2), 1 - sqrt(2)/2, -2 + 3*sqrt(2)/2, sqrt(-7 + 5*sqrt(2))*(1 + sqrt(2)), sqrt(-7 + 5*sqrt(2)))

r1 = 0.414, r2 = 0.172, r3 = 0.293, r4 = 0.121, x3 = 0.644, x4 = 0.267

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 circle(ox, oy, r, color=:red; beginangle=0, endangle=360, fill=false)
 θ = beginangle:0.1:endangle
 x = r.*cosd.(θ)
 y = r.*sind.(θ)
  if fill
      plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5, seriestype=:shape, fillcolor=color)
  else
      plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
  end
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)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (r1, r2, r3, r4, x3, x4) = res[1]
   @printf("r1 = %.3f, r2 = %.3f, r3 = %.3f, r4 = %.3f, x3 = %.3f, x4 = %.3f\n", r1, r2, r3, r4, x3, x4)
   plot()
   circle(0, 0, 1, :black)
   circle(0, 1 - r1, r1)
   circle(0, -1 + r1, r1)
   circle(0, 0, r2, :blue)
   circle(x3, r3, r3, :magenta)
   circle(x3, -r3, r3, :magenta)
   circle(-x3, r3, r3, :magenta)
   circle(-x3, -r3, r3, :magenta)
   circle(x4, r4, r4, :green)
   circle(x4, -r4, r4, :green)
   circle(-x4, r4, r4, :green)
   circle(-x4, -r4, r4, :green)
   if more == true
       point(0, 1-r1, "甲: 1-r1 ", :red, :right)
       point(0, r2, "乙:r2", :blue, :center)
       point(x3, r3, "丙:(x3,r3)", :magenta, :center)
       point(x4, r4, " 丁:(x4,r4)", :green)
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
   else
       plot!(showaxis=false)
   end
end;

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

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

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