TheSwamp
Code Red => VB(A) => Topic started by: rude dog on January 31, 2009, 12:29:12 PM
-
If I have a line that
is made like this:
LineStart= 1.0,1.0,0.0
LineEnd= 13.0,4.0,4.0
and I would like to define polar points from 'LineStart' at:
PtA= 4.0,1.75,1.0
PtB= 7.0,2.5,2.0
PtC= 10.0,3.25,3.0
How do I aprroach this?
-
A plane can be made to include any 3 points.
You can make a ucs that satisfies that plane.
then you can convert the points form wcs->ucs coordinates
Now they will all have the same z value and polarpoint will work.
Now you transform the points back to world (wcs)
This is not the most efficient solution, it's probably the the solution that requires the least knowledge of math.
What are you trying to do with the points?
-
Take a line that is a certain length and break it up into smaller lengths the user defines.
-
Not Pretty But something along these lines:
Public Sub PickPointsPipe()
Dim objCirc As AcadCircle
Dim dblOD As Double
Dim varFtpt As Variant
Dim varSdpt As Variant
Dim objTempLine As AcadLine
Dim dblDist As Double
Dim dblRunLeng As Double
Dim dblFullStk As Double
Dim dblAngle As Double
Dim varLastPt As Variant
Dim objEnts() As AcadEntity
Dim objPipe As Acad3DSolid
Dim varRegions As Variant
Dim varItem As Variant
On Error GoTo Done
With ThisDrawing
varFtpt = .Utility.GetPoint(, vbCr & " Pick point to start pipe: ")
varSdpt = .Utility.GetPoint(varFtpt, vbCr & " Pick point to end pipe: ")
Dim dblVec(0 To 2) As Double
dblVec(0) = varSdpt(0) - varFtpt(0): dblVec(1) = varSdpt(1) - varFtpt(1): dblVec(2) = varSdpt(2) - varFtpt(2)
Dim dblVal As Double
dblVal = Sqr(dblVec(0) * dblVec(0) + dblVec(1) * dblVec(1) + dblVec(2) * dblVec(2))
Dim dblVecNorm(0 To 2) As Double
dblVecNorm(0) = dblVec(0) / dblVal: dblVecNorm(1) = dblVec(1) / dblVal: dblVecNorm(2) = dblVec(2) / dblVal
End With
With ThisDrawing
Set objTempLine = .ModelSpace.AddLine(varFtpt, varSdpt)
dblDist = objTempLine.Length
dblRunLeng = 10#
dblAngle = .Utility.AngleFromXAxis(varFtpt, varSdpt)
dblFullStk = (dblDist / dblRunLeng)
objTempLine.Delete
varLastPt = .Utility.PolarPoint(varFtpt, dblAngle, dblRunLeng)
Dim counter As Double
counter = 1
Do While dblFullStk > counter
varLastPt = .Utility.PolarPoint(varFtpt, dblAngle, dblRunLeng)
Set objTempLine = .ModelSpace.AddLine(varFtpt, varLastPt)
Set objCirc = .ModelSpace.AddCircle(varFtpt, 1#)
objCirc.Normal = dblVecNorm
ReDim objEnts(0)
Set objEnts(0) = objCirc
varRegions = .ModelSpace.AddRegion(objEnts)
Set objPipe = .ModelSpace.AddExtrudedSolid(varRegions(0), dblRunLeng, 0)
objPipe.Update
objTempLine.Delete
Debug.Print varLastPt(0) & "," & varLastPt(1) & "," & varLastPt(2)
varFtpt = varLastPt
counter = counter + 1
For Each varItem In objEnts
varItem.Delete
Next
For Each varItem In varRegions
varItem.Delete
Next
Loop
End With
Done:
If Err Then MsgBox Err.Description
End Sub
-
X = X1 + distance / dLength * DX is the math you need and you are already using it.
There is no need for angles or polar points
below is an example
Function PointOnLineAtDistance(P1, P2, Dist As Double) As Variant
Dim P3(2) As Double
Dim dblLength As Double
dblLength = Length(P1, P2)
P3(0) = P1(0) + (Dist / dblLength) * (P2(0) - P1(0))
P3(1) = P1(1) + (Dist / dblLength) * (P2(1) - P1(1))
P3(2) = P1(2) + (Dist / dblLength) * (P2(2) - P1(2))
PointOnLineAtDistance = P3
End Function
-
Sometime I cant see the forrest through the trees...Thank you
I was hesitant about posting what I had (because it was so scattered) and I am still learning...glad I did!
-
We are all still learning.
Without posting your code I wouldn't have really understood your question.
I have often gone out of my way to resist the temptation to insert temporary objects to help with the math.
You could easily get rid of the line.