exercises from “Linear Algebra”, David Poole, 2006, Thomson

To find a number half-way between two numbers, add them then divide by two. Similarly, to find a midpoint of a line add the coordinates of the endpoints and divide by two.

Since a vector and a point have the same data structure, to find a vector half way between two other vectors, it has a different notation, but it breaks down to the same calculation.

We use the standard notation to show points as Capitals. Vectors to those points are lower case. VBA vector variables are lower case. VBA points will be as ptA, ptB etc, although since Points and Vectors in VBA have identical data structures we dont need to double declare. Vectors are mobile. The algebra of vectors does not depend on position. To draw them in autocad, a start position is specified.

Given two vectors a and b, the vector from a to b is b-a. This is practically the definition of a vector. In autocad a line has a startpoint and endpoint. The vector represented by that line is the difference from start to finish. The line can be moved or copied, and as long as it is not rotated or stretched, it represents the same vector. The total difference of the coordinates is the vector. Autocad Lines have properties of DeltaX, DeltaY and DeltaZ. These do not change when the line is copied and moved. They are the vector.

If we take a line with endpoints A and B, the vectors from the origin to those points are a and b. If we define a vector from the origin to the midpoint of the line as m, then the vector from a to m is m-a. m-a is already defined as 1/2 (b-a), so we have an equation that we can simplify to get the result – given two points A and B, the vector to the midpoint is m = 1/2 (a + b).

In this diagram a parallelogram diagonal shows the result of adding two vectors. When they are subtracted the result is represented by the diagonal between them. The diagonals bisect each other, so that in this case half of the long diagonal, 1/2 (a + b) is equal to m.

To find a point a third of the way between two points, or in general any fraction, requires to go back to the original equation.

Vector algebra can be used to prove and illustrate geometry.

A line from the midpoints of two sides of a triangle is half the length and parallel to the other side. Here we use the vector midpoint formula to find the midpoints of sides of a triangle, then subtract those vectors from each other to find a vector equation for the line joining them, then simplify that equation to see that it is exactly one half the length of the other side. The figure is drawn in vba and the same calculation made to verify the result.

An arbitrary quadrilateral which has its midpoints joined forms a parallelogram. The vectors on opposite sides are compared in VBA to see if they have identical values.

doing the calculation g = 1/3 (a + b + c) also draws a vector to the centroid G.

I had trouble with this one. The altitude of a triangle is a line from a vertex perpendicular to the other side. The 3 altitudes intersect at a point called the orthocenter. Prove this by finding the intersection of two altitudes and show the third one goes thru the point and is perpendicular to the third side. I could not figure out how to get vector h. I could use actual data to prove it for this one specific case, but not a general vector equation. i believe solution lies with the similarity of triangles – the projection of AB on BC at P is the same as the projection of BH on BC at P, so that AB dot BC is equal to BH dot BC. and the same argument for AB on AC. In lieu of that, i show the drawing of the figure in autocad VBA.

The triangle vertexes are given. The altitude starts at a vertex. It terminates at a right angle to the other side, which has known endpoints and hence a known slope. The slope of the altitude is the negative inverse of the slope of the line it meets. Autocad has a method to determine an intersection between two drawing objects, called InterSectWith. I use it twice, once to find the orthocenter intersection of altitudes point H, then to find the intersection with the far side.

First the line is drawn from the vertex using the slope and an arbitrary length. That establishes actual autocad entities to use with the InterSectWith method. I draw all lines with a function that returns a line object, and once the proper endpoint is found, its easy to change the endpoint property of the line.

slope = tan theta = delta y / delta x

Slope and tangent work with undirected lines. On the graph, its the angle the line makes with the positive x axis from -90 to +90. Given the slope as a simple number, we have lost the ability to know what quadrant the coordinates were in. If you wanted to draw vectors, you would have to analyze the x and y values independently. I dont worry about that here. If the line is drawn the wrong way, I change the length of its sign. The bottom line is that slope and tangent work with the same set of angles, and to find the angle from the slope, use the arctangent function ATN.

theta = ATN (slope)

See the function for line3 which accepts a startpoint, a slope and a length to draw a line.

code after the picture

Sub test7() '5 p30 altitude of triangle from vertex to perpendicular init 'orthocenter Dim ptH() As Double 'lines Dim AB As AcadLine, BC As AcadLine, CA As AcadLine Dim AP As AcadLine, BQ As AcadLine, CR As AcadLine 'slopes Dim m_AB As Double, m_BC As Double, m_CA As Double 'points Dim ptA() As Double, ptB() As Double, ptC() As Double Dim ptP() As Double, ptQ() As Double, ptR() As Double ptA = pt(2, 1, 0) ptB = pt(9, 3, 0) ptC = pt(3, 6, 0) Set AB = line1(ptA, ptB) Set BC = line1(ptB, ptC) Set CA = line1(ptC, ptA) m_AB = slope(ptA, ptB) m_BC = slope(ptB, ptC) m_CA = slope(ptC, ptA) Set AP = line3(ptA, (-1 / m_BC), 5) Set BQ = line3(ptB, (-1 / m_CA), -5) Set CR = line3(ptC, (-1 / m_AB), -5) ptH = intersectWith(AP, BQ) AP.EndPoint = ptH BQ.EndPoint = ptH CR.EndPoint = ptH ' txt1 "A", ptA, 0.375 ' txt1 "B", ptB, 0.375 ' txt1 "C", ptC, 0.375 ' txt1 "H", ptH, 0.375 ptP = intersectWith(AP, BC) ptQ = intersectWith(BQ, CA) ptR = intersectWith(CR, AB) AP.EndPoint = ptP BQ.EndPoint = ptQ CR.EndPoint = ptR Update End Sub Function line1(startpt() As Double, endpt() As Double, Optional strlayer As Variant) As AcadLine Set line1 = acadDoc.ModelSpace.AddLine(startpt, endpt) If Not IsMissing(strlayer) Then line1.Layer = strlayer End If g_pt = endpt End Function Function line3(pt1() As Double, slope As Double, leng As Double) As AcadLine Dim pt2() As Double, theta As Double theta = Atn(slope) pt2 = acadDoc.Utility.PolarPoint(pt1, theta, leng) Set line3 = acadDoc.ModelSpace.AddLine(pt1, pt2) g_pt = pt2 End Function Function slope(pt1() As Double, pt2() As Double) As Double Dim x As Double, y As Double, z As Double y = pt2(1) - pt1(1) x = pt2(0) - pt1(0) If x = 0 Then MsgBox "div by zero in slope" Exit Function Else slope = y / x End If End Function Function intersectWith(L1 As AcadLine, L2 As AcadLine) As Double() Dim ptH(0 To 2) As Double Dim intpoints As Variant intpoints = L1.intersectWith(L2, acExtendBoth) ' copied changed from autocad activex help for Intersectwith Dim I As Integer, j As Integer If VarType(intpoints) <> vbEmpty Then For I = LBound(intpoints) To UBound(intpoints) ptH(0) = intpoints(j) ptH(1) = intpoints(j + 1) ptH(2) = intpoints(j + 2) I = I + 2 j = j + 3 Next Else MsgBox "did not find intersect" End If intersectWith = ptH End Function

Prove the perpendicular bisectors of a triangle are concurrent. The point K is called the circumcenter. A circle with center at K passes through the vertexes.

code to draw (not prove) after the picture

Sub test8() '6 p30 perpendicular bisector of 3 sides of triangle are concurrent init 'circumcenter Dim ptK() As Double 'lines Dim AB As AcadLine, BC As AcadLine, CA As AcadLine Dim PK As AcadLine, QK As AcadLine, RK As AcadLine 'slopes Dim m_AB As Double, m_BC As Double, m_CA As Double 'points Dim ptA() As Double, ptB() As Double, ptC() As Double Dim ptP() As Double, ptQ() As Double, ptR() As Double ptA = pt(2, 1, 0) ptB = pt(9, 3, 0) ptC = pt(3, 6, 0) Set AB = line1(ptA, ptB) Set BC = line1(ptB, ptC) Set CA = line1(ptC, ptA) m_AB = slope(ptA, ptB) m_BC = slope(ptB, ptC) m_CA = slope(ptC, ptA) ptP = midpoint(ptB, ptC) ptQ = midpoint(ptC, ptA) ptR = midpoint(ptA, ptB) Set PK = line3(ptP, (-1 / m_BC), 5) Set QK = line3(ptQ, (-1 / m_CA), -5) Set RK = line3(ptR, (-1 / m_AB), -5) ptK = intersectWith(PK, QK) PK.EndPoint = ptK QK.EndPoint = ptK RK.EndPoint = ptK Update End Sub

finally, another unfinished project, prove the lines joining the midpoints of a quadrilateral bisect each other.

Sub test10() '8 p30 lines joining midpoints of opposite sides of a quadrilateral bisect each other init Dim ptZ() As Double 'lines Dim AB As AcadLine, BC As AcadLine, CD As AcadLine, DA As AcadLine Dim PR As AcadLine, QS As AcadLine Dim ptA() As Double, ptB() As Double, ptC() As Double, ptD() As Double Dim ptP() As Double, ptQ() As Double, ptR() As Double, ptS() As Double ptA = pt(2, 8, 0) ptB = pt(10, 7, 0) ptC = pt(12, 2, 0) ptD = pt(1, 3, 0) Set AB = line1(ptA, ptB) Set BC = line1(ptB, ptC) Set CD = line1(ptC, ptD) Set DA = line1(ptD, ptA) ptP = midpoint(ptA, ptB) ptQ = midpoint(ptB, ptC) ptR = midpoint(ptC, ptD) ptS = midpoint(ptD, ptA) Set PR = line1(ptP, ptR) Set QS = line1(ptQ, ptS) txt1 "A", ptA, 0.375 txt1 "B", ptB, 0.375 txt1 "C", ptC, 0.375 txt1 "D", ptD, 0.375 txt1 "P", ptP, 0.375 txt1 "Q", ptQ, 0.375 txt1 "R", ptR, 0.375 txt1 "S", ptS, 0.375 ptZ = intersectWith(PR, QS) txt1 "Z", ptZ, 0.375 Update End Sub