×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Cross product of vectors - macro

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

(OP)
I have simple program where I have a vector which represent normal of slected plane.Now I want to make a cross product between nthis vector and for example one vector of origin (x or y or z).How make taht?please help me...Below is a source code:
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

You've got 99% of what you need here.  All that remains is for you to do the cross product.  Declare a variable as

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

Sorry, brain fart.  What you want is more like:

CODE

Dim swCPwithX as SldWorks.MathVector
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

(OP)
Oh, Thanks handleman.I amke something like You... but your proposition is good. I think about this, that one of component to  cross product (You proposs swCPwithX or swCPwithY or swCPwithZ) will be perpendicular to normal of selected surafce... I try use function in MathVector but there are nothing... (I think so..) How make taht?For example: if normal of surface is (1,0,0) that vector which I use to cross product is (0,1,0) or (0,0,1).If You know how make it, please help... Thanks

RE: Cross product of vectors - macro

I'm don't understand what you are asking.  The result "swCPwithX" will be perpendicular to the plane normal and to the X axis of the part coordinate system.  Similar for swCPwithY and swCPwithZ.  I'm not sure what end result you seek.

RE: Cross product of vectors - macro

(OP)
Yes, You have right handleman.But this is only good when normal is (0,0,1) or (0,1,0) or (1,0,0).And how willbe perpendicular vector when normal willbe for example (0.4251, 0, 0.687)?

RE: Cross product of vectors - macro

I'm afraid I still don't understand what you are trying to do.  Why are you interested in finding the cross product?

RE: Cross product of vectors - macro

(OP)
So, I want obtain a coordinates system where one of axis is normal to surface(vector of normal). Next axis must be a orthogonal to this normal. When I have this two vectors I can obtain third vector using cross product...

RE: Cross product of vectors - macro

One vector is not enough to define a coordinate system.  If your normal vector is the X-axis of your new coordinate system then the Y and Z axes can still be any direction along the surface.  You will have to do two cross products.  The first one will be with one of the part's axes and the other will be a cross of the result and the original normal vector.  Something like:

CODE

dim MyNewXaxis as SldWorks.MathVector
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

(OP)
Ok handleman, Your proposition is good.Thanks for Your time and patience:)!
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources