All the basic trig graphing functions are in one sub, called from a combo box on the form. Error checking for div by zero and max line length is not implemented yet.

Option Explicit Sub init_trig() Call connect_acad Xmin = frm_trig.txt_xmin Xmax = frm_trig.txt_xmax X_inc = frm_trig.txt_xinc A = 0 B = 0 C = 0 D = 0 End Sub Sub draw_t01() Call init_trig Dim fnx As String A = frm_trig.txt_a1.Value B = frm_trig.txt_b1.Value Max_L = frm_trig.txt_line_limit fnx = frm_trig.cbo_sin.Value Select Case fnx Case "SIN" funcname = "T_01" Case "COS" funcname = "T_02" Case "TAN" funcname = "T_03" Case "COT" funcname = "T_04" Case "SEC" funcname = "T_05" Case "CSC" funcname = "T_06" End Select strLabel = "Y = " & A & " * " & fnx & " " & B & " * X" Call draw_trig(funcname) End Sub Sub draw_t07() Call init_trig funcname = "T_07" A = frm_trig.txt_a7.Value B = frm_trig.txt_b7.Value C = frm_trig.txt_c7.Value D = frm_trig.txt_d7.Value Call draw_trig(funcname) End Sub Sub draw_t08() Call init_trig funcname = "T_08" A = frm_trig.txt_a8.Value B = frm_trig.txt_b8.Value C = frm_trig.txt_c8.Value Call draw_trig(funcname) End Sub Sub draw_trig(funcname As String) Dim X As Double, Y As Double Dim plineobj As AcadLWPolyline Dim pt() As Double Dim i As Integer, numpts As Integer numpts = (Xmax - Xmin) / X_inc 'number of line segments numpts = numpts + 1 'one more pt than line segment ReDim pt(1 To numpts * 2) 'store x and y for one pt For i = 1 To numpts X = Xmin + ((i - 1) * X_inc) Y = Application.Run(funcname, X) pt(i * 2 - 1) = X: pt(i * 2) = Y Next i Set plineobj = acadDoc.ModelSpace.AddLightWeightPolyline(pt) Update If frm_trig.chk_box_label_graph = True Then label_graph End If 'just save this here for now 'If distance(X1, Y1, X2, Y2) < Max_L Then 'Call line(X1, Y1, X2, Y2) 'If Err.Number = 11 Then End Sub Function T_01(X As Double) As Double T_01 = A * Sin(B * X) End Function Function T_02(X As Double) As Double T_02 = A * Cos(B * X) End Function Function T_03(X As Double) As Double T_03 = A * Tan(B * X) End Function Function T_04(X As Double) As Double T_04 = A * (1 / Tan(B * X)) End Function Function T_05(X As Double) As Double T_05 = A * (1 / Cos(B * X)) End Function Function T_06(X As Double) As Double T_06 = A * (1 / Sin(B * X)) End Function Function T_07(X As Double) As Double T_07 = Sin(A * X) + Sin(B * X) + Sin(C * X) + D End Function Function T_08(X As Double) As Double T_08 = A * Sin(B / (C * X)) End Function Function distance(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double) As Double distance = ((X2 - X1) ^ 2 + (Y2 - Y1) ^ 2) ^ (1 / 2) End Function

Advertisements