Option Explicit
Public Function IsArc(PolyLin As AcadLWPolyline, Optional Vertex As
Integer) As Boolean
Dim Bulg As Double
If Vertex = Empty Then Vertex = 0
Bulg = PolyLin.GetBulge(Vertex)
If bulge <> 0 Then IsArc = True
End Function
Public Function IsSemiCircle(PolyLin As AcadLWPolyline, Optional Vertex
As Integer) As Boolean
Dim Bulg As Double
If Vertex = Empty Then Vertex = 0
Bulg = PolyLin.GetBulge(Vertex)
If bulge = 1 Or Bulg = -1 Then IsArc = True
End Function
Public Function ClockWise(PolyLin As AcadLWPolyline, Optional Vertex As
Integer) As Boolean
Dim Bulg As Double
If Vertex = Empty Then Vertex = 0
Bulg = PolyLin.GetBulge(Vertex)
If bulge < 0 Then ClockWise = True
End Function
Public Function Radius(PolyLin As AcadLWPolyline, Optional Vertex As
Integer) As Double
Dim PolyPts As Variant
Dim PolySp(0 To 2) As Double
Dim PolyEp(0 To 2) As Double
Dim Lin1 As AcadLine
Dim Ang As Double
Dim IsoAng As Double
Dim Bulg As Double
If Vertex = Empty Then Vertex = 0
Bulg = PolyLin.GetBulge(Vertex)
Ang = Atn(Bulg) * 4
IsoAng = Ang / 3.141592654 * 180
If IsoAng < 0 Then
IsoAng = (IsoAng + 180) / 2
Else
IsoAng = (180 - IsoAng) / 2
End If
IsoAng = IsoAng / 180 * 3.141592654
PolyPts = PolyLin.Coordinates
PolySp(0) = PolyPts(0): PolySp(1) = PolyPts(1)
PolyEp(0) = PolyPts(2): PolyEp(1) = PolyPts(3)
Set Lin1 = ThisDrawing.ModelSpace.AddLine(PolySp, PolyEp)
Radius = (Lin1.Length / 2) / Cos(IsoAng)
Lin1.Delete
End Function
Public Function CenterPt(PolyLin As AcadLWPolyline, Optional Vertex As
Integer) As Variant
Dim PolyPts As Variant
Dim PolySp(0 To 2) As Double
Dim PolyEp(0 To 2) As Double
Dim Lin1 As AcadLine
Dim Ang As Double
Dim IsoAng As Double
Dim Radius As Double
Dim ClockWise As Boolean
Dim RadAng As Double
Dim Bulg As Double
If Vertex = Empty Then Vertex = 0
Bulg = PolyLin.GetBulge(Vertex)
PolyPts = PolyLin.Coordinates
PolySp(0) = PolyPts(0): PolySp(1) = PolyPts(1)
PolyEp(0) = PolyPts(2): PolyEp(1) = PolyPts(3)
Set Lin1 = ThisDrawing.ModelSpace.AddLine(PolySp, PolyEp)
Ang = Atn(Bulg) * 4
IsoAng = Ang / 3.141592654 * 180
If IsoAng < 0 Then
IsoAng = (IsoAng + 180) / 2
ClockWise = True
Else
IsoAng = (180 - IsoAng) / 2
End If
IsoAng = IsoAng / 180 * 3.141592654
If ClockWise Then
RadAng = Lin1.Angle + IsoAng + 3.141592654
Else
RadAng = Lin1.Angle - IsoAng + 3.141592654
End If
Radius = (Lin1.Length / 2) / Cos(IsoAng)
CenterPt = ThisDrawing.Utility.PolarPoint(PolyEp, RadAng, Radius)
Lin1.Delete
End Function
dgleason wrote:
> I am creating an arc / polyline (with bulge) slicer,
> how do I calculate the origin and start angle for a polyline with a
> bulge. I saw some AutoLISP code, but I cant read it.
>
> I found the following, but nothing for the start angle and obviously I
> can find the direction from the sign of the bulge factor..
>
> IncludedAngle = 4 * Atan(Abs(bulge factor))
> Angle = .5PI - .5IncludedAngle
> Chord = Distance(Point1, Point2)
> Radius = .5Chord / Cos(Angle)
>
> Thanks
>
> Dave
>
The bulge is the tangent of 1/4 of the included angle for the arc
between the selected vertex and the next vertex in the polyline's vertex
list. A negative bulge value indicates that the arc goes clockwise from
the selected vertex to the next vertex. A bulge of 0 indicates a
straight segment, and a bulge of 1 is a semicircle.
So the arctangent of the bulge multiplied by 4 gives the arc's angle.
This angle and the line bisecting the chord yields enough info to form 2
right triangles and calculate startangle, endangle, radius, centerpoint,
ect.
Using the value of the bulge and the location of the vertices, you can
calculate the direction of the arc and on which side of the polyline the
centerpoint falls. Hope this helps.
-Josh
dgleason wrote:
> Hi Josh, thanks for your help.. You were right
> I am looking for the "centerpoint and
> the equivalent to the startangle property for
> the arc".
>
> Unfortunately the project that I am writing is outside of AutoCad, so I
> really don't have access to AutoCad objects.
>
> Do you know the math behind:
> "CenterPt = ThisDrawing.Utility.PolarPoint(PolyEp, RadAng, Radius)"
>
> and
>
> "ThisDrawing.ModelSpace.AddLine(PolySp, PolyEp)"
>
> Basically I need to calculate the origin and startangle so
> that when I create a polyline "representation" of the
> polyline(with a bulge) that I read in, I know where to start, ie. in the
> which quadrant etc.
>