Public Xmin As Double Public Xmax As Double Public X_inc As Double Sub init_scale() Call connect_acad Xmin = frm_Graph.txt_xmin Xmax = frm_Graph.txt_xmax X_inc = frm_Graph.txt_xinc End Sub Sub draw_parabola() Call init_scale Dim a As Double, b As Double, c As Double a = frm_Graph.txt_a1 b = frm_Graph.txt_b1 c = frm_Graph.txt_c1 Call parabola(Xmin, Xmax, a, b, c, X_inc) End Sub Sub draw_xcube() Call init_scale Dim a As Double, b As Double, c As Double, d As Double a = frm_Graph.txt_a2 b = frm_Graph.txt_b2 c = frm_Graph.txt_c2 d = frm_Graph.txt_d2 Call x_cube(Xmin, Xmax, a, b, c, d, X_inc) End Sub Sub draw_xpower() Call init_scale Dim a As Double, n As Double a = frm_Graph.txt_a3 n = frm_Graph.txt_n3 Call x_power(Xmin, Xmax, a, n, X_inc) End Sub Sub draw_hyperbola() Call init_scale Dim a As Double, b As Double a = frm_Graph.txt_a4 b = frm_Graph.txt_b4 Call hyperbola(Xmin, Xmax, a, b, X_inc) End Sub Sub draw_ellipse() Call init_scale Dim a As Double, b As Double a = frm_Graph.txt_a5 b = frm_Graph.txt_b5 Call ellipse(a, b, X_inc) End Sub '****************************** Public strLabel As String '****************************** Sub parabola(min_x As Double, max_x As Double, a As Double, b As Double, c As Double, X_inc As Double) 'y = ax^2 + bx + c Dim X As Double, Y As Double Dim plineobj As AcadLWPolyline Dim pt() As Double Dim i As Integer, numpts As Integer numpts = (max_x - min_x) / X_inc 'this is the number of line segments numpts = numpts + 1 'there is always one more pt than line segment ReDim pt(1 To numpts * 2) 'to store both x and y for one pt For i = 1 To numpts X = min_x + ((i - 1) * X_inc) Y = a * X ^ 2 + b * X + c pt(i * 2 - 1) = X: pt(i * 2) = Y Next i Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt) Update strLabel = "Y= " & a & "X^2 + " & b & "X + " & c End Sub Sub x_cube(min_x As Double, max_x As Double, a As Double, b As Double, c As Double, d As Double, X_inc As Double) 'y = ax^3 + bx^2 + cx + d Dim X As Double, Y As Double Dim plineobj As AcadLWPolyline Dim pt() As Double Dim i As Integer, numpts As Integer numpts = (max_x - min_x) / X_inc 'this is the number of line segments numpts = numpts + 1 'there is always one more pt than line segment ReDim pt(1 To numpts * 2) 'to store both x and y for one pt For i = 1 To numpts X = min_x + ((i - 1) * X_inc) Y = a * X ^ 3 + b * X ^ 2 + c * X + d pt(i * 2 - 1) = X: pt(i * 2) = Y Next i Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt) Update strLabel = "Y= " & a & "X^3 + " & b & "X^2 + " & c & "X + " & d End Sub Sub x_power(min_x As Double, max_x As Double, a As Double, n As Double, X_inc As Double) 'y = ax^n Dim X As Double, Y As Double Dim plineobj As AcadLWPolyline Dim pt() As Double Dim i As Integer, numpts As Integer numpts = (max_x - min_x) / X_inc 'this is the number of line segments numpts = numpts + 1 'there is always one more pt than line segment ReDim pt(1 To numpts * 2) 'to store both x and y for one pt For i = 1 To numpts X = min_x + ((i - 1) * X_inc) Y = a * X ^ n pt(i * 2 - 1) = X: pt(i * 2) = Y Next i Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt) Update strLabel = "Y= " & a & "X^" & n End Sub Sub hyperbola(min_x As Double, max_x As Double, a As Double, b As Double, X_inc As Double) 'y= (((x^2) * (a^2) / (b^2)) + a^2)^(1/2) Dim X As Double, Y As Double Dim plineobj As AcadLWPolyline Dim pt() As Double Dim i As Integer, numpts As Integer numpts = (max_x - min_x) / X_inc 'this is the number of line segments numpts = numpts + 1 'there is always one more pt than line segment ReDim pt(1 To numpts * 2) 'to store both x and y for one pt For i = 1 To numpts X = min_x + ((i - 1) * X_inc) Y = (((X ^ 2) * (a ^ 2) / (b ^ 2)) + a ^ 2) ^ (1 / 2) pt(i * 2 - 1) = X: pt(i * 2) = Y Next i Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt) For i = 1 To numpts X = min_x + ((i - 1) * X_inc) Y = -(((X ^ 2) * (a ^ 2) / (b ^ 2)) + a ^ 2) ^ (1 / 2) pt(i * 2 - 1) = X: pt(i * 2) = Y Next i Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt) Update strLabel = "Y^2/(" & a & "^2)" & " - " & "(X^2/" & b & "^2)" & " = 1 " End Sub Sub ellipse(a As Double, b As Double, t_inc As Double) 'x = a * Cos(t) 'y = b * Sin(t) 'where 0<t<6.283 which is 2 pi Dim X As Double, Y As Double, t As Double Dim plineobj As AcadLWPolyline Dim pt() As Double Dim i As Integer, numpts As Integer Dim max_t As Double max_t = 2 * 3.14159265359 numpts = (max_t) / t_inc 'this is the number of line segments numpts = numpts + 1 'there is always one more pt than line segment ReDim pt(1 To numpts * 2) 'to store both x and y for one pt For i = 1 To numpts t = 0 + (i - 1) * t_inc X = a * Cos(t) Y = b * Sin(t) pt(i * 2 - 1) = X: pt(i * 2) = Y Next i Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt) Update strLabel = "X= " & a & "cos t" & " Y= " & b & "sin t" & " 0<t<2 pi" End Sub

Advertisements