Working with ICurve methods
Do the following steps to work with ICurve methods:
- Define a new point as the origin of the circular arc.
- Create a circular arc using the origin point and a predefined angle.
- Call GetSubcurve of ICircularArc to get the sub-curve of the circular arc.
- Call other methods to show the length and IsClosed properties.
- Call the QueryTangent andQueryNormal methods to get tangent and normal somewhere along the curve.
- Call QueryPoint to get the point along the extent of tangent from ToPoint.
- Call QueryPointAndDistance to find the point on the extended curve nearest to the input point and the distance between those points.
- Call ReverseOrientation to reverse the orientation of the curve.
The following code example shows how to use the methods on ICurve:
[C#] 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);
}
[VB.NET] Public Sub CurveDemo()
Dim pCArc As ICircularArc
pCArc=New CircularArc
Dim pOrigin As IPoint
pOrigin=New Point
Dim pSubCArc As ICircularArc
Dim pTangent As ILine
Dim pNormal As ILine
pTangent=New Line
pNormal=New Line
Dim pTanPoint As IPoint
pTanPoint=New Point
Dim bAsRatio As Boolean
Dim pNearPoint As IPoint
pNearPoint=New Point
Dim DistOnCurve As Double
Dim NearDist As Double
Dim bRight As Boolean
Dim Pi As Double
Pi=4 * Math.Atan(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(esriSegmentExtension.esriExtendTangentAtFrom, 0.3, True, 20, pTangent)
pCArc.QueryNormal(esriSegmentExtension.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(esriSegmentExtension.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(esriSegmentExtension.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(ByVal pPoint As IPoint) As String
OutputPoint="(" & pPoint.X & ", " & pPoint.Y & ")"
End Function
Public Function OutputLine(ByVal pLine As ILine) As String
Dim pFromPoint As IPoint
Dim pToPoint As IPoint
pFromPoint=New Point
pToPoint=New Point
pLine.QueryFromPoint(pFromPoint)
pLine.QueryToPoint(pToPoint)
OutputLine="From " & OutputPoint(pFromPoint) & " to " & OutputPoint(pToPoint)
End Function
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |
Engine Developer Kit | Engine |