두점, 수평력을 입력하여 그리는 카테나리(현수선) VBA 입니다.
(이미지 추가가 여의치 않아 블로그 링크합니다. 아래 두번째 링크는 웹상에서도 그래프를 볼수 있습니다)
Private Function COSH(p As Double)
COSH = (Exp(p) + Exp(-p)) / 2
End Function
Private Function SINH(p As Double)
SINH = (Exp(p) – Exp(-p)) / 2
End Function
Private Function ASINH(p As Double)
ASINH = Log(p + Sqr(p * p + 1))
End Function
Sub catenary2() ‘2points & Horizontal Force
Dim Pnt1, Pnt3 As Variant ‘2points for catenary
Pnt1 = ThisDrawing.Utility.GetPoint(, “1st Point”)
Pnt3 = ThisDrawing.Utility.GetPoint(, “2nd Point”)
Dim w As Double
w = InputBox(“Uniform load”)
Dim H As Double
H = InputBox(“Horizontal Force”)
Dim x1, x3, y1, y3, plusx, plusy As Double
x1 = Pnt1(0) – Pnt1(0): x3 = Pnt3(0) – Pnt1(0)
y1 = Pnt1(1) – Pnt1(1): y3 = Pnt3(1) – Pnt1(1)
Dim L, hh As Double ‘hh는 높이
L = x3 – x1
hh = y3 – y1
Dim aa, bb, cc As Double
aa = H / w
bb = L / 2 – aa * ASINH(hh / (2 * aa * SINH(L / 2 / aa)))
Dim n As Integer ‘등분’
n = InputBox(“What is the number of divided catenary?”)
Dim interval As Double
interval = (Pnt3(0) – Pnt1(0)) / n
Dim polyPnt() As Double
ReDim polyPnt(2 * n + 1) As Double
Dim i As Integer
For i = 0 To n
polyPnt(i * 2) = x1 + interval * i
polyPnt(i * 2 + 1) = aa * (COSH((polyPnt(i * 2) – bb) / aa) – COSH(bb / aa))
Next i
Dim Opnt1(2) As Double
Dim Opnt2(2) As Double
Opnt1(0) = 0: Opnt1(1) = 0: Opnt1(2) = 0
Opnt2(0) = Pnt1(0): Opnt2(1) = Pnt1(1): Opnt2(2) = 0
Dim polyObj As AcadLWPolyline
Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(polyPnt)
polyObj.Move Opnt1, Opnt2
End Sub