Option Explicit '---------------------------- Type point x As Double y As Double End Type '---------------------------- Const DtoR = 3.14159265358979 / 180 Const TOP = 1 Const BOTTOM = -1 Dim row As Long Dim rnge As Object Dim work As Variant Sub main() Dim A As point, B As point, C As point '頂点 Dim lngth As Double '輪の長さ Dim wa As Double '2頂点からの距離の和 Dim ab As Double, bc As Double, ca As Double '辺の長さ Dim aa As Double, bb As Double, cc As Double '切片 Dim x As Double, y As Double Dim i As Long, j As Long, tmp_row As Long '----------初期値取得-------------- A.x = Cells(1, 8).Value A.y = Cells(1, 9).Value B.x = Cells(2, 8).Value B.y = Cells(2, 9).Value C.x = Cells(3, 8).Value C.y = Cells(3, 9).Value '----------基本量計算-------------- aa = A.y bb = -B.x cc = C.x ab = Sqr(aa * aa + bb * bb) bc = cc + bb ca = Sqr(cc * cc + aa * aa) Cells(4, 8).Value = ab + bc + ca MsgBox ("三辺の和は " & Str(ab + bc + ca)) Do lngth = Val(InputBox("輪の長さを入力して下さい.")) If (lngth > (ab + bc + ca)) Then Exit Do End If Loop Cells(5, 8).Value = lngth '---------------------------------- Set rnge = Range("A1:B1100") work = rnge.Value row = 0 Range("A:B").ClearContents '----------領域Ⅰ------------------ wa = lngth - (ab + bc) Call plot(C, A, wa, TOP) For i = 1 To row x = work(i, 1) y = work(i, 2) If (y >= ((aa / bb) * x + aa)) Or (y < 0) Then work(i, 1) = "" work(i, 2) = "" End If Next i tmp_row = row '----------領域Ⅱ------------------ wa = lngth - bc Call plot(B, C, wa, TOP) For i = tmp_row + 1 To row x = work(i, 1) y = work(i, 2) If (y < ((aa / bb) * x + aa)) Or (y <= (-(aa / cc) * x + aa)) Then work(i, 1) = "" work(i, 2) = "" End If Next i tmp_row = row '----------領域Ⅲ------------------ wa = lngth - (ca + bc) Call plot(A, B, wa, TOP) For i = tmp_row + 1 To row x = work(i, 1) y = work(i, 2) If (y > (-(aa / cc) * x + aa) Or (y <= 0)) Then work(i, 1) = "" work(i, 2) = "" End If Next i tmp_row = row '----------領域Ⅳ------------------ wa = lngth - ca Call plot(A, C, wa, BOTTOM) For i = tmp_row + 1 To row x = work(i, 1) y = work(i, 2) If ((y > 0) Or (y <= (aa / bb) * x + aa)) Then work(i, 1) = "" work(i, 2) = "" End If Next i tmp_row = row '----------領域Ⅴ------------------ wa = lngth - (ca + ab) Call plot(C, B, wa, BOTTOM) For i = tmp_row + 1 To row x = work(i, 1) y = work(i, 2) If ((y > (aa / bb) * x + aa) Or (y >= -(aa / cc) * x + aa)) Then work(i, 1) = "" work(i, 2) = "" End If Next i tmp_row = row '----------領域Ⅵ------------------ wa = lngth - ab Call plot(B, A, wa, BOTTOM) For i = tmp_row + 1 To row x = work(i, 1) y = work(i, 2) If ((y < -(aa / cc) * x + aa) Or (y >= 0)) Then work(i, 1) = "" work(i, 2) = "" End If Next i '---------------------------------- j = 0 For i = 1 To row If (work(i, 1) <> "") Then j = j + 1 work(j, 1) = work(i, 1) work(j, 2) = work(i, 2) work(i, 1) = "" work(i, 2) = "" End If Next i rnge.Value = work Application.Calculation = xlCalculationAutomatic End Sub Sub plot(p1 As point, p2 As point, lngth As Double, flag As Long) Dim x As Double, y As Double, xx As Double, yy As Double Dim f As Double, A As Double, B As Double, theta As Double Dim i As Long, start As Long, finish As Long f = Sqr((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)) / 2 A = Sqr(lngth * lngth / 4) B = Sqr(lngth * lngth / 4 - f * f) theta = Atn((p2.y - p1.y) / (p1.x - p2.x)) If (flag = TOP) Then start = 0 finish = 180 Else start = 180 finish = 360 End If For i = start To finish row = row + 1 x = A * Cos(i * DtoR) '中心が原点にある楕円 y = B * Sin(i * DtoR) xx = x * Cos(-theta) - y * Sin(-theta) '回転 yy = x * Sin(-theta) + y * Cos(-theta) x = xx + ((p1.x + p2.x) / 2) '平行移動 y = yy + ((p1.y + p2.y) / 2) work(row, 1) = x work(row, 2) = y Next i End Sub