This document is archived and information here might be outdated. Recommended version. |
ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IC > IConstructPoint Interface > IConstructPoint.ConstructAngleDistance Method (ArcObjects .NET 10.4 SDK) |
Constructs a point at a specified angle (in radians) from the horizontal axis and a specified distance away from the input point.
[Visual Basic .NET] Public Sub ConstructAngleDistance ( _ ByVal p As IPoint, _ ByVal inAngle As Double, _ ByVal distance As Double _ )
[C#] public void ConstructAngleDistance ( IPoint p, double inAngle, double distance );
[C++]
HRESULT ConstructAngleDistance(
IPoint* p,
double inAngle,
double distance
);
[C++]
Parameters p
p is a parameter of type IPoint inAngle inAngle is a parameter of type double distance distance is a parameter of type double
The ConstructAngleDistance method, given a point (p), construct another point at an angle (inangle) and a distance(distance).
Angle in radians and distance in map units. The angle is measured counter-clockwise from the horizontal line and can be negative. If the distance is negative then the opposite direction is assumed (same as angle + PI).
// select a point in ArcMap and calculate a new point with the
// angle of 45 degrees and distance on 250 map units.
public void ConstructAngleDistance()
{
IMxDocument mxDocument=m_application.Document as IMxDocument;
IMap map=mxDocument.FocusMap;
ISelection featureSelection=map.FeatureSelection;
IEnumFeature featureEnumerator=featureSelection as IEnumFeature;
featureEnumerator.Reset();
IFeature currentFeature=featureEnumerator.Next();
double distance=250;
double angle=45;
while (currentFeature != null)
{
if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
{
IPoint startPoint=currentFeature.Shape as IPoint;
System.Windows.Forms.MessageBox.Show("Start Point: " + startPoint.X + ", " + startPoint.Y + "\n" +
"Angle: " + angle + "\n" + "Distance: " + distance);
IPoint point=_ConstructAngleDistance(startPoint, angle, distance);
System.Windows.Forms.MessageBox.Show("x,y=" + point.X + "," + point.Y);
}
currentFeature=featureEnumerator.Next();
}
}
private IPoint _ConstructAngleDistance(IPoint point, double angle, double distance)
{
//Convert the angle degrees to radians
double angleRad=angle * 2 * Math.PI / 360;
IConstructPoint construcionPoint=new PointClass();
construcionPoint.ConstructAngleDistance(point, angleRad, distance);
return construcionPoint as IPoint;
}
'+++ select a point in ArcMap and calculate a new point with the
'+++ angle of 45 degrees and distance on 100 map units.
Public Sub t_ConstructAngleDistance(ByRef pMXDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument)
On Error GoTo Errorhandler
Dim pEnumFeat As ESRI.ArcGIS.Geodatabase.IEnumFeature
Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature
Dim pSelection As ESRI.ArcGIS.Carto.ISelection
Dim pMap As ESRI.ArcGIS.Carto.IMap
Dim pPoint As ESRI.ArcGIS.Geometry.IPoint
Dim pStart As ESRI.ArcGIS.Geometry.IPoint
Dim dDist As Long
Dim dAngle As Long
pMap=pMXDoc.FocusMap
pSelection=pMap.FeatureSelection
pEnumFeat=pSelection
pEnumFeat.Reset()
pFeature=pEnumFeat.Next
dDist=250
dAngle=45
While Not pFeature Is Nothing
If pFeature.Shape.GeometryType=ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint Then
pStart=pFeature.Shape
Debug.Print(1, "Start Point:" & pStart.X & "," & pStart.Y & vbCrLf & _
"Angle:" & dAngle & vbCrLf & "Distance:" & dDist)
pPoint=PtConstructAngleDistance(pStart, dAngle, dDist)
Debug.Print(1, "x,y=" & pPoint.X & "," & pPoint.Y & vbCrLf)
End If
pFeature=pEnumFeat.Next
End While
Exit Sub
Errorhandler:
MsgBox(Err.Number & "..." & Err.Description)
Exit Sub
End Sub
Public Function PtConstructAngleDistance(ByVal pPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal dAngle As Long, ByVal dDist As Long) As ESRI.ArcGIS.Geometry.IPoint
Const PI=3.14159265358979
Dim dAngleRad As Double
Dim pCPoint As ESRI.ArcGIS.Geometry.IConstructPoint
pCPoint=New ESRI.ArcGIS.Geometry.Point
dAngleRad=dAngle * 2 * PI / 360 'Convert the angle degrees to radians
pCPoint.ConstructAngleDistance(pPoint, dAngleRad, dDist)
PtConstructAngleDistance=pCPoint
End Function
IConstructPoint Interface | IConstructPoint.ConstructAlong Method