Code with perpendicluar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have 3 point A, B, C
and then I calculate another point - D, then D on AB, and CD perpendicluar with AB
In this Code, Mypoint is a class,like Point-class, with some attributes was added,
so you dont need care about it
Function perpendicularPointAndLine(startPoint As MyPoint, endPoint As MyPoint, anotherPoint As MyPoint, namePoint As String)
' A B C D
Dim a(0 To 2) As Double
a(0) = startPoint.point.Coordinates(0)
a(1) = startPoint.point.Coordinates(1)
a(2) = startPoint.point.Coordinates(2)
Dim b(0 To 2) As Double
b(0) = endPoint.point.Coordinates(0)
b(1) = endPoint.point.Coordinates(1)
b(2) = endPoint.point.Coordinates(2)
Dim C(0 To 2) As Double
C(0) = anotherPoint.point.Coordinates(0)
C(1) = anotherPoint.point.Coordinates(1)
C(2) = anotherPoint.point.Coordinates(2)
'NOW I HAVE COORDINATE OF POINTS A, B, AND C'
AND THEN I CALCULATE COORIDINATE OF D
Dim vectorCP(0 To 2) As Double
vectorCP(0) = b(0) - a(0)
vectorCP(1) = b(1) - a(1)
vectorCP(2) = b(2) - a(2)
'so D on AB then
' d(0) = a(0) + vectorCP(0) * t
' d(1) = a(1) + vectorCP(1) * t
' d(2) = a(2) + vectorCP(2) * t
'vector CD
'd(0) - c(0) = vectorCP(0) * t+ a(0) - c(0)
'd(1) - c(1) = vectorCP(1) * t+ a(1) - c(1)
'd(2) - c(2) = vectorCP(2) * t+ a(2) - c(2)
Dim c1(0 To 2) As Double
c1(0) = a(0) - C(0)
c1(1) = a(1) - C(1)
c1(2) = a(2) - C(2)
'vector CD
'vectorCP(0) * t+ c1(0)
'vectorCP(1) * t+ c1(1)
'vectorCP(2) * t+ c1(2)
'CD and AB perpendicular
'we have vector(CD) * vector(AB) = 0
'vectorCP(0)^2 *t + c1(0)*vectorCP(0) + vectorCP(1)^2t + c1(1)*vectorCP(1) + vectorCP(2)^2*t +c1(2)*vectorCP(2) = 0
't(vectorCP(0)^2 +vectorCP(1)^2 +vectorCP(2)^2) = -c1(0)*vecCP(0) -c1(1) *vecCP(1) -c1(2) *vectorCP(2)
Dim t As Double
t = (-c1(0) * vectorCP(0) - c1(1) * vectorCP(1) - c1(2) * vectorCP(2))
t = t / (vectorCP(0) * vectorCP(0) + vectorCP(1) * vectorCP(1) + vectorCP(2) * vectorCP(2))
Dim perpenPoint(0 To 2) As Double
perpenPoint(0) = vectorCP(0) * t + a(0)
perpenPoint(1) = vectorCP(1) * t + a(1)
perpenPoint(2) = vectorCP(2) * t + a(2)
' I think PROBLEM is t variables
' I think have a wrong when I try to calculate t
' if I set t = 0.5 it will draw D at Midpoint of AB
Set ArrayPoint(countPoint).point = ThisDrawing.ModelSpace.AddPoint(perpenPoint)
With ArrayPoint(countPoint)
.intID = countPoint
.strName = namePoint
End With
countPoint = countPoint + 1
' twoPoint countPoint - 1, anotherPoint.intID
ThisDrawing.Application.update
'Ket thuc
'
End Function