I have derived an angle from an entity in UCS. Can someone tell me how to convert this angle to the correct angle in WCS?
Thanks,
Frank
Solved! Go to Solution.
Solved by Balaji_Ram. Go to Solution.
Solved by FrankLenoir. Go to Solution.
Hi,
project these entities to WCS and get then the angle 😉
You don't need to add these projected entities to the database, you can .dispose them on end of your calculation.
- alfred -
Hi Alfred,
The function I am working on works like this: the user picks a random point on an entity. The angle is derived from the entity at the picked point. So I only have the angle as result. But when the user works in a UCS I have to translate the angle to WCS to be able to work with it.
I would prefere to calculate the new angle.
Frank
Hi,
how do you request the angle now? Just one point is not enough for me, an angle could be calculated between to straight elements. Could you show this code-snippet?
- alfred -
Hi Alfred,
Here is the code I use
Public Shared Function GetAngleAtPointOnLine() As AngleAtPointOnLineClass Dim retValue As New AngleAtPointOnLineClass Try Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim myEd As Editor = acDoc.Editor Dim bObject As New PromptNestedEntityOptions("") Dim opt As PromptPointOptions = New PromptPointOptions("Select point on object: ") bObject.NonInteractivePickPoint = myEd.GetPoint(opt).Value bObject.UseNonInteractivePickPoint = True Dim bRes As PromptNestedEntityResult = myEd.GetNestedEntity(bObject) If bRes.Status = PromptStatus.OK Then Using myTrans As Transaction = acDoc.TransactionManager.StartTransaction 'the return value of your nested selection may not always be one of 'those things that derives from curve, so you should check it first! If bRes.ObjectId.ObjectClass.IsDerivedFrom(Curve.GetClass(GetType(Curve))) Then Dim crv As Curve = myTrans.GetObject(bRes.ObjectId, OpenMode.ForRead, False, True) Dim wcsPoint As Point3d = bRes.PickedPoint.TransformBy(myEd.CurrentUserCoordinateSystem) Dim myFirstDerivative As Vector3d = crv.GetFirstDerivative(wcsPoint) retValue.Angle = Math.Atan2(CDbl(myFirstDerivative.Y), CDbl(myFirstDerivative.X)) * (180 / Math.PI) retValue.point = New Point3d(bRes.PickedPoint.X, bRes.PickedPoint.Y, bRes.PickedPoint.Z) End If End Using End If retValue.HasError = False Catch ex As Exception retValue.HasError = True Debug.Print(ex.Message) End Try Return retValue End Function End Class Public Class AngleAtPointOnLineClass Public HasError As Boolean Public Angle As Double Public point As Point3d End Class
I found parts of the code on internet. I more or less understand what is happening. As you can see the angle is derived from the exact location on the object. In WCS this function works fine. In UCS the point comes out correctly, but the angle not. The angle needs to be corrected to an angle in WCS.
Frank
Hi Frank,
The derivative vector is always in WCS. To convert it to UCS can you try this ?
<code>
Dim myFirstDerivative AsVector3d = crv.GetFirstDerivative(wcsPoint)
Dim wcs2ucs AsMatrix3d
wcs2ucs = myEd.CurrentUserCoordinateSystem.Inverse()
myFirstDerivative = myFirstDerivative.TransformBy(wcs2ucs)
</code>
Thanks very much Balaji.
The CurrentUserCoordinateSystem.Inverse function returns the desired vector for calculating the correct angle.
Frank