ArcObjects Library Reference  (Geometry)    

esriGeometry_ICurve_Example

[Visual Basic 6.0]

'This example demonstrates how to use the methods on ICurve

Public Sub CurveDemo()
   Dim pCArc As ICircularArc
   Set pCArc = New CircularArc
   Dim pOrigin As IPoint
   Set pOrigin = New Point
   Dim pSubCArc As ICircularArc
   Dim pTangent As ILine
   Dim pNormal As ILine
   Set pTangent = New Line
   Set pNormal = New Line
   Dim pTanPoint As IPoint
   Set pTanPoint = New Point
   Dim bAsRatio As Boolean
   Dim pNearPoint As IPoint
   Set pNearPoint = New Point
   Dim DistOnCurve As Double
   Dim NearDist As Double
   Dim bRight As Boolean
   Dim Pi As Double
  
   Pi = 4 * Atn(1)
  
   pOrigin.PutCoords 0, 0
   pCArc.PutCoordsByAngle pOrigin, 0, 2 * Pi, 100   '0 to 2Pi = Full-arc
  
   'pSubCArc is Set by GetSubcurve.  Half-arc (Pi/2 to 3Pi/2)
   pCArc.GetSubcurve 0.25, 0.75, True, pSubCArc
  
   MsgBox "Main: Closed? " & pCArc.IsClosed & vbCrLf & "Length: " & pCArc.Length & vbCrLf _
          & "Sub: Closed? " & pSubCArc.IsClosed & vbCrLf & "Length: " & pSubCArc.Length
  
   'Subcurve From point (0.0) is the same as the main curve point at 0.25 (25%)
   'Subcurve To point (1.0) is the same as the main curve point at 0.75 (75%)
   MsgBox "Subcurve From: " & OutputPoint(pSubCArc.FromPoint) & vbCrLf & _
          "Subcurve To: " & OutputPoint(pSubCArc.ToPoint)
  
   'Query the tangent (length 20) of the point 0.3 (30%) along the subcurve
   'Query the normal (length 10) of the point 0.4 (40%) along the main curve
   'Note: 0.3 (30%) along the subcurve is the same point as the point
   '      0.4 (40%) along the main curve
   pSubCArc.QueryTangent esriExtendTangentAtFrom, 0.3, True, 20, pTangent
   pCArc.QueryNormal esriExtendTangentAtFrom, 2 * pCArc.Length / 5, False, 10, pNormal
  
   MsgBox "Tangent: " & OutputLine(pTangent) & vbCrLf & _
          "Normal: " & OutputLine(pNormal)
  
   'Finds the point along the To tangent extended 20% beyond the ToPoint
   pCArc.QueryPoint esriExtendTangentAtTo, 1.2, True, pTanPoint
  
   MsgBox "Point on Tangent: " & OutputPoint(pTanPoint)
  
   'Finds the point on the Circular Arc nearest to the point extended tangentially
   'Returns the nearest point, the distance to the point, the distance along the curve,
   '  whether the point is on the right side of the curve, and AsRatio indicator
   pCArc.QueryPointAndDistance esriNoExtension, pTanPoint, bAsRatio, pNearPoint, DistOnCurve, NearDist, bRight
  
   MsgBox "Nearest Point: " & OutputPoint(pNearPoint) & vbCrLf & _
          "Distance: " & NearDist
  
   pSubCArc.ReverseOrientation  'pSubCArc now is the arc from 3Pi/2 to Pi/2
End Sub

Public Function OutputPoint(pPoint As IPoint) As String
   OutputPoint = "(" & pPoint.X & ", " & pPoint.Y & ")"
End Function
Public Function OutputLine(pLine As ILine) As String
   Dim pFromPoint As IPoint
   Dim pToPoint As IPoint
   Set pFromPoint = New Point
   Set pToPoint = New Point
  
   pLine.QueryFromPoint pFromPoint
   pLine.QueryToPoint pToPoint
   OutputLine = "From " & OutputPoint(pFromPoint) & " to " & OutputPoint(pToPoint)
End Function


[C#]
//This example demonstrates how to use the methods on ICurve
public void DemoCurve()
{
  IPoint origin = new PointClass();
  origin.PutCoords(0, 0);
  ICircularArc circularArc = new CircularArcClass();
  circularArc.PutCoordsByAngle(origin, 0, 2 * Math.PI, 10);   //0 to 2Pi = Full-arc
  //subCircularArc is Set by GetSubcurve.  Half-arc (Pi/2 to 3Pi/2)
  ICurve subCircularArc;
  circularArc.GetSubcurve(0.25, 0.75, true, out subCircularArc );
  System.Windows.Forms.MessageBox.Show("Main: Closed? " + circularArc.IsClosed + "\n" +
                                  "Length: " + circularArc.Length + "\n" +
                                  "Sub: Closed? " + subCircularArc.IsClosed + "\n" +
                                  "Length: " + subCircularArc.Length
                                  );
  //Subcurve From point (0.0) is the same as the main curve point at 0.25 (25%)
  //Subcurve To point (1.0) is the same as the main curve point at 0.75 (75%)
  System.Windows.Forms.MessageBox.Show("Subcurve From: " + OutputPoint(subCircularArc.FromPoint) + "\n" +
                                  "Subcurve To: " + OutputPoint(subCircularArc.ToPoint) 
                                  );
  //Query the tangent (length 20) of the point 0.3 (30%) along the subcurve
  //Query the normal (length 10) of the point 0.4 (40%) along the main curve
  //Note: 0.3 (30%) along the subcurve is the same point as the point
  //      0.4 (40%) along the main curve
  ILine tangent = new LineClass(); ;
  subCircularArc.QueryTangent(esriSegmentExtension.esriExtendTangentAtFrom, 0.3, true, 20, tangent);
  ILine normal = new LineClass(); ;
  circularArc.QueryNormal(esriSegmentExtension.esriExtendTangentAtFrom, 2 * circularArc.Length / 5, false, 10, normal);
  System.Windows.Forms.MessageBox.Show("Tangent: " + OutputLine(tangent) + "\n" +
                                 "Normal: " + OutputLine(normal)
                                );
  //Finds the point along the To tangent extended 20% beyond the ToPoint
  IPoint tangentPoint = new PointClass();
  circularArc.QueryPoint(esriSegmentExtension.esriExtendTangentAtTo, 1.2, true, tangentPoint);
  System.Windows.Forms.MessageBox.Show("Point on Tangent: " +OutputPoint(tangentPoint));
  //Finds the point on the Circular Arc nearest to the point extended tangentially
  //Returns the nearest point, the distance to the point, the distance along the curve,
  //whether the point is on the right side of the curve, and AsRatio indicator
  bool asRatio = false;
  IPoint nearestPoint =new PointClass();
  double distanceOnCurve = 0;
  double nearestDistance = 0;
  bool isRightSide = false;
  circularArc.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, tangentPoint, asRatio, nearestPoint, ref distanceOnCurve, ref nearestDistance, ref isRightSide);
  System.Windows.Forms.MessageBox.Show("Nearest Point: " + OutputPoint(nearestPoint)+ "\n" +
                                  "Distance: " + nearestDistance
                                  );
  //subCircularArc now is the arc from 3Pi/2 to Pi/2
  subCircularArc.ReverseOrientation();  
}
private String OutputPoint(IPoint point)
{
  return "(" + point.X + ", " + point.Y + ")";
}
private String OutputLine(ILine line)
{
  IPoint fromPoint = new PointClass();
  IPoint toPoint = new PointClass();
  line.QueryFromPoint(fromPoint);
  line.QueryToPoint(toPoint);
  return "From " + OutputPoint(fromPoint) + " to " + OutputPoint(toPoint);
}

[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.