Cross product of vectors - macro
Cross product of vectors - macro
(OP)
Hi, I wan to build a macro which give me new vector using function MathVector.Cross . One of input vector is a normal of surface (for example plane) and a second is one of axis of origin. So, I want obtain vector emergent with this two inputs vectors... If this possible?If You have any ideas please describe... thanks






RE: Cross product of vectors - macro
htt
Ken
RE: Cross product of vectors - macro
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim swSurf As SldWorks.Surface
Dim vPlane As Variant
Dim swMathUtil As SldWorks.MathUtility
Dim nVector(2) As Double
Dim vVector As Variant
Dim swFlatNorm As SldWorks.MathVector
Dim ArrayData As Variant
Set swApp = Application.SldWorks
Set swMathUtil = swApp.GetMathUtility
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFace = swSelMgr.GetSelectedObject5(1)
Set swSurf = swFace.GetSurface
If swSurf.IsPlane Then
vPlane = swSurf.PlaneParams
swApp.SendMsgToUser " Selected Surface - PLANE " _
& vbCrLf & vbCrLf & " Normal = (" & vPlane(0) & ", " & vPlane(1) & ", " & vPlane(2) & ")" _
& vbCrLf & vbCrLf & " Root = (" & vPlane(3) * 1000# & ", " & vPlane(4) * 1000# & ", " & vPlane(5) * 1000# & ") mm" _
& vbCrLf & vbCrLf & " File = " & swModel.GetPathName
End If
nVector(0) = vPlane(0): nVector(1) = vPlane(1): nVector(2) = vPlane(2):
vVector = nVector
Set swFlatNorm = swMathUtil.CreateVector((vVector))
ArrayData = swFlatNorm.ArrayData
swApp.SendMsgToUser " Selected Surface - PLANE " _
& vbCrLf & vbCrLf & " Vector of normal = (" & ArrayData(0) & ", " & ArrayData(1) & ", " & ArrayData(2) & ")"
GoTo CleanUp
CleanUp:
Set swApp = Nothing
Set swMathUtil = Nothing
Set swModel = Nothing
Set swSelMgr = Nothing
Set swFace = Nothing
End Sub
RE: Cross product of vectors - macro
Dim swCPVector As As SldWorks.MathVector
Then, once you've created swFlatNorm with swMathUtil.CreateVector you can cross it with a (1,1,1) vector like so:
set swCPVector = swFlatNorm.Cross(swMathUtil.CreateVector(Array(1,1,1)))
RE: Cross product of vectors - macro
CODE
Dim swCPwithY as SldWorks.MathVector
Dim swCPwithZ as SldWorks.MathVector
.
.
.
.
set swCPwithX = swFlatNorm.Cross(swMathUtil.CreateVector(Array(1,0,0)))
set swCPwithY = swFlatNorm.Cross(swMathUtil.CreateVector(Array(0,1,0)))
set swCPwithZ = swFlatNorm.Cross(swMathUtil.CreateVector(Array(0,0,1)))
RE: Cross product of vectors - macro
RE: Cross product of vectors - macro
RE: Cross product of vectors - macro
RE: Cross product of vectors - macro
RE: Cross product of vectors - macro
RE: Cross product of vectors - macro
CODE
dim MyNewYaxis as SldWorks.MathVector
dim MyNewZaxis as SldWorks.MathVector
.
.
.
.
Set MyNewXaxis = swFlatNorm
set MyNewYaxis = MyNewXaxis.Cross(swMathUtil.CreateVector(Array(1,0,0)))
'[check here to make sure that the value of
'MyNewYaxis is not (0,0,0). If so, cross MyNewXaxis
'with (0,1,0) to get value for MyNewYaxis
Set MyNewZaxis = MyNewXaxis.cross(MyNewYaxis)
RE: Cross product of vectors - macro