- '''''''''------- Vector Methods --------------'''''''''''
- Public Function VecNorm(vec() As Double) As Double()
- 'Normalises the incoming vector.
- Dim vecn(2) As Double
- Dim unit As Double
- unit = Sqr(vec(0) * vec(0) + vec(1) * vec(1) + vec(2) * vec(2))
- vecn(0) = vec(0) / unit: vecn(1) = vec(1) / unit: vecn(2) = vec(2) / unit
- VecNorm = vecn
- End Function
- Function VecCross(v1() As Double, v2() As Double) As Variant
- Dim vec(2)
- vec(0) = v1(1) * v2(2) - v2(1) * v1(2)
- vec(1) = v1(2) * v2(0) - v2(2) * v1(0)
- vec(2) = v1(0) * v2(1) - v2(0) * v1(1)
- VecCross = vec
- End Function
- '''''''''--------- Matrix Methods ------------'''''''''''
- Public Function xFormMat(vx() As Double, vy() As Double, vz() As Double) As Variant
- 'Uses the incoming vectors to transform the entity being passed in
- Dim mat(0 To 3, 0 To 3) As Double
- mat(0, 0) = vx(0): mat(0, 1) = vy(0): mat(0, 2) = vz(0): mat(0, 3) = 0#
- mat(1, 0) = vx(1): mat(1, 1) = vy(1): mat(1, 2) = vz(1): mat(1, 3) = 0#
- mat(2, 0) = vx(2): mat(2, 1) = vy(2): mat(2, 2) = vz(2): mat(2, 3) = 0#
- mat(3, 0) = 0#: mat(3, 1) = 0#: mat(3, 2) = 0#: mat(3, 3) = 1#
- xFormMat = mat
- End Function
- Public Function GetMatFromLine(line As AcadLine) As Variant
- 'builds a matrix based on the line's sp, ep and normal
- Dim mat(0 To 3, 0 To 3) As Double
- Dim vx(2) As Double, vy(2) As Double, vz(2) As Double
- 'get the lines ep-sp vector to create the z axis:
- vz(0) = line.EndPoint(0) - line.StartPoint(0)
- vz(1) = line.EndPoint(1) - line.StartPoint(1)
- vz(2) = line.EndPoint(2) - line.StartPoint(2)
- 'normalise it:
- Dim retvec As Variant
- retvec = VecNorm(vz)
- vz(0) = retvec(0): vz(1) = retvec(1): vz(2) = retvec(2)
- 'get the line's normal for the x vector:
- vx(0) = line.Normal(0)
- vx(1) = line.Normal(1)
- vx(2) = line.Normal(2)
- 'create the y vector by xproduct of z over x:
- retvec = VecCross(vz, vx)
- vy(0) = retvec(0): vy(1) = retvec(1): vy(2) = retvec(2)
- 'normalise it:
- retvec = VecNorm(vy)
- vy(0) = retvec(0): vy(1) = retvec(1): vy(2) = retvec(2)
- 'plug 'em into the matrix:
- mat(0, 0) = vx(0): mat(0, 1) = vy(0): mat(0, 2) = vz(0): mat(0, 3) = 0#
- mat(1, 0) = vx(1): mat(1, 1) = vy(1): mat(1, 2) = vz(1): mat(1, 3) = 0#
- mat(2, 0) = vx(2): mat(2, 1) = vy(2): mat(2, 2) = vz(2): mat(2, 3) = 0#
- mat(3, 0) = 0#: mat(3, 1) = 0#: mat(3, 2) = 0#: mat(3, 3) = 1#
- GetMatFromLine = mat
- End Function
我还有很多要添加的内容,将发布它们,但在我产生太多垃圾之前,我希望得到一些建议