Parallelogram in TurboCAD Pro 7.1 - Ty Harness
I wrote this macro to answer a question in the Yahoo TurboCAD users forum, simply draw a parallelogram knowing the side lengths and a diagonal. The cosine rule sprang to mind and it's only a 5min job to write a simple macro like this. I think it'll be limited use for anyone else but it is a nice example of applying the cosine rule to a problem.




The macro (tcm) code can be downloaded from the Yahoo TurboCAD users forum.

Form Code


Private Sub calculatefromabc() On Error GoTo eh Dim a As Double, b As Double, c As Double Dim X As Double, AngA As Double Dim w As Double, h As Double a = CDbl(aTextBox.Text) b = CDbl(bTextBox.Text) c = CDbl(cTextBox.Text) X = (-a * a + b * b + c * c) / (2 * b * c) AngA = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1) 'arccosine h = b * Sin(AngA) w = b * Cos(AngA) hTextBox.Text = CStr(h) wTextBox.Text = CStr(w) Label6.Caption = "-" Exit Sub eh: Label6.Caption = "Error" wTextBox.Text = "" hTextBox.Text = "" End Sub
Private Sub drawParallelogram(c As Double, w As Double, h As Double) ActiveDrawing.Graphics.AddLineSingle 0, 0, 0, c, 0, 0 'base line c ActiveDrawing.Graphics.AddLineSingle 0, 0, 0, w, h, 0 'diag line b ActiveDrawing.Graphics.AddLineSingle c, 0, 0, w, h, 0 'line a ActiveDrawing.Graphics.AddLineSingle w, h, 0, w - c, h, 0 'paralell c ActiveDrawing.Graphics.AddLineSingle 0, 0, 0, w - c, h, 0 ' paralell a End Sub
Private Sub aTextBox_Change() calculatefromabc End Sub
Private Sub bTextBox_Change() calculatefromabc End Sub
Private Sub CommandButton1_Click() On Error GoTo eh: Dim a As Double, c As Double Dim w As Double, h As Double c = CDbl(cTextBox.Text) w = CDbl(wTextBox.Text) h = CDbl(hTextBox.Text) drawParallelogram c, w, h Exit Sub eh: Label6.Caption = "Cannot draw parallelogram" End Sub
Private Sub CommandButton2_Click() Unload Me End Sub
Private Sub cTextBox_Change() calculatefromabc End Sub
Private Sub UserForm_Click() End Sub
Private Sub UserForm_Initialize() calculatefromabc End Sub

Module Code


Sub tydrawparallel() frmparallel.Show End Sub


[Home] [Mechanics] [Welding] [Software] [CAD] [Math]