My question this time is to figure out how to properly place (create) a cylinder in space to exactly fit into a line (so the line is exactly in the center of the cylinder). Here is what I am working with:
http://i60.tinypic.com/2njxa95.png
As you can see, I have tried to create the cylinders from the axis X (1,0,0), Y(0,1,0), and Z(0,0,1).
Some gave a different result than others.
I have both start and end points of the line [(x,y,z) values], the angle of it (degrees/rad)
As for the cylinder, I am able to create it based off of radius, height, location in space, workplane x and z axis.
I am able to rotate the cylinder using a function .SetRotate(Axis, vPoint, deg)
Which works based off an axis, location (same used to create) and the angle in degrees.
I am using the same angle value I am obtaining from the line, and my guess is I must somehow figure out the correct axis (the same one as the line).
I am trying to achieve the following:
http://i62.tinypic.com/n62aa8.png[
^]
If you need more information please let me know. Thanks.
EDIT: My code that might help:
Dim PickObj As New VISIPick
Dim FaceList As New VISIList
Dim db As New VISIDatabase
Dim OldElList As New VISIList
Dim mwp, mpw, matT, matR As New VISIMatrix
Dim P2 As New VISIPoint
Dim Axis As New VISIVector
PickObj.Message = "Pick a Line"
If PickObj.Pick = False Then
Exit Sub
End If
FaceList.Init(5, LTYPE_FACE)
db.WorkDBKey = PickObj.PickedKey
db.GetElement()
WPL.GetDefault()
WPL.CreateFromZAxis(PickObj.PickedPoint, WPL.ZAxis)
WPL.WorkPlaneWorld(mwp, mpw)
If WPL.LastError <> V_NOERROR Then
MsgBox(WPL.LastError)
Exit Sub
End If
lblDebug.Text = "(" & WPL.Origin.X.ToString() & "," & WPL.Origin.Y.ToString() & "," & WPL.Origin.Z.ToString() & ")" & vbNewLine & _
WPL.XAxis.CX.ToString() & " " & WPL.XAxis.CY.ToString() & " " & WPL.XAxis.CZ.ToString() & vbNewLine & _
" " & WPL.YAxis.CX.ToString() & " " & WPL.YAxis.CY.ToString() & " " & WPL.YAxis.CZ.ToString() & vbNewLine & _
" " & WPL.ZAxis.CX.ToString() & " " & WPL.ZAxis.CY.ToString() & " " & WPL.ZAxis.CZ.ToString()
Dim x, y, z, rad, deg As Double
x = db.WorkElement.EndPoint.X - db.WorkElement.StartPoint.X
y = db.WorkElement.EndPoint.Y - db.WorkElement.StartPoint.Y
z = db.WorkElement.EndPoint.Z - db.WorkElement.StartPoint.Z
rad = (Math.Asin(z / Math.Sqrt((x ^ 2) + (y ^ 2) + (z ^ 2)))).ToString()
deg = (rad * (180 / Math.PI)).ToString()
If (deg > 0) Then
vPoint.Put(db.WorkElement.StartPoint.X, db.WorkElement.StartPoint.Y, db.WorkElement.StartPoint.Z)
Else
vPoint.Put(db.WorkElement.EndPoint.X, db.WorkElement.EndPoint.Y, db.WorkElement.EndPoint.Z)
End If
lblDeg.Text = deg.ToString()
SolFac.CreateCylinder(0.006, db.WorkElement.Length, vPoint, WPL.XAxis, WPL.ZAxis)
vList.Init(10, LTYPE_BODY)
Axis.Put(1, 0, 0)
If SolFac.LastError <> V_NOERROR Then
MsgBox(SolFac.LastError)
Else
vList.AddItem(SolFac.Result)
mwp.SetRotate(Axis, vPoint, deg)
SolFac.WorkMatrix = mwp
SolFac.ApplyMatrix(vList)
Appl.UpdateSolidsOnScreen()
End If