Convertion degree to azimuth

5460
6
04-06-2013 12:35 AM
oyleiste
Occasional Contributor
Dear All,

I have 2 points which creates a line. I want to get angle of line and then draw another line with +30 degree. I can do it but I always get 7-10 degree more than actual angle.

I get distance between 2 points using IMeasurementTool.ConstructByPoints, then I get angle using IConstructAngle.ConstructLine. Here I have angle and distance between 2 points. Now, I'll give ConstructByPointDistAngle first point, distance and angle to get second point. Now I calculate angle between first point and result point of ConstructByPointDistAngle but I get angle with 8.266233055077116 degree difference.

I think I'm not convert degree to azimuth correctly. Any idea?

FYI: azimuth is degrees clockwise from north

Here is my working code with comment and Debug results. Red texts are debug results.
PointClass p1 = new PointClass();
PointClass p2 = new PointClass();
// Add data to points for test
p1.PutCoords(34.481560, 41.515391);
p2.PutCoords(34.702832, 41.795668);

ILine lineForAngle = new Line();
IMeasurementTool measurementTool = new MeasurementToolClass();

measurementTool.ConstructByPoints(p1, p2);
// Here we calculate distance between two points: (p1, p2)
double distance = measurementTool.Distance;

GeometryEnvironment geoEnv = new GeometryEnvironment();
IConstructAngle angleCalculator = (IConstructAngle)geoEnv;

lineForAngle.PutCoords(p1, p2);
// Here we calculate angle of line between (p1, p2) and the positive x-axis
double angle = angleCalculator.ConstructLine(lineForAngle);
// Convert radian to degree
angle *= 180 / Math.PI; // = 51.709836807757121 Degree
// Convert angle to azimuth (still degree)
angle = 90 - angle;     // = 38.290163192242879

// Here I give first point (p1), azimuth and distance to get p2
measurementTool.ConstructByPointDistAngle(p1, distance, angle);

geoEnv = new GeometryEnvironment();
angleCalculator = (IConstructAngle)geoEnv;

// I put p1 and result point of measurementTool which is a point
lineForAngle.PutCoords(p1, measurementTool.ToPoint);

// Now I have calculate angle between p1 and result of measurementTool
angle = angleCalculator.ConstructLine(lineForAngle);
angle *= 180 / Math.PI; // = 43.443603752680005

// first angle - result angle:
// 51.709836807757121 - 43.443603752680005 = 8.266233055077116
0 Kudos
6 Replies
AlexeySubbotin
New Contributor III
Dear All, 

I have 2 points which creates a line. I want to get angle of line and then draw another line with +30 degree. I can do it but I always get 7-10 degree more than actual angle. 

I get distance between 2 points using   IMeasurementTool.ConstructByPoints, then I get angle using   IConstructAngle.ConstructLine. Here I have angle and distance between 2 points. Now, I'll give   ConstructByPointDistAngle first point, distance and angle to get second point. Now I calculate angle between first point and result point of   ConstructByPointDistAngle but I get angle with 8.266233055077116 degree difference. 

I think I'm not convert degree to azimuth correctly. Any idea? 

FYI: azimuth is degrees clockwise from north 

Here is my working code with comment and   Debug results. Red texts are debug results. 
PointClass p1 = new PointClass();
PointClass p2 = new PointClass();
// Add data to points for test
p1.PutCoords(34.481560, 41.515391);
p2.PutCoords(34.702832, 41.795668);

ILine lineForAngle = new Line();
IMeasurementTool measurementTool = new MeasurementToolClass();

measurementTool.ConstructByPoints(p1, p2);
// Here we calculate distance between two points: (p1, p2)
double distance = measurementTool.Distance;

GeometryEnvironment geoEnv = new GeometryEnvironment();
IConstructAngle angleCalculator = (IConstructAngle)geoEnv;

lineForAngle.PutCoords(p1, p2);
// Here we calculate angle of line between (p1, p2) and the positive x-axis
double angle = angleCalculator.ConstructLine(lineForAngle);
// Convert radian to degree
angle *= 180 / Math.PI; // = 51.709836807757121 Degree
// Convert angle to azimuth (still degree)
angle = 90 - angle;     // = 38.290163192242879

// Here I give first point (p1), azimuth and distance to get p2
measurementTool.ConstructByPointDistAngle(p1, distance, angle);

geoEnv = new GeometryEnvironment();
angleCalculator = (IConstructAngle)geoEnv;

// I put p1 and result point of measurementTool which is a point
lineForAngle.PutCoords(p1, measurementTool.ToPoint);

// Now I have calculate angle between p1 and result of measurementTool
angle = angleCalculator.ConstructLine(lineForAngle);
angle *= 180 / Math.PI; // = 43.443603752680005

// first angle - result angle:
// 51.709836807757121 - 43.443603752680005 = 8.266233055077116


Hi!

To the point of your problem.
You use the intricate algorithm. I think it's easier to use IConstructPoint.ConstructDeflection method with the negative value of the angle (in radians) and the necessary distance.
0 Kudos
oyleiste
Occasional Contributor
Hi!

To the point of your problem.
You use the intricate algorithm. I think it's easier to use IConstructPoint.ConstructDeflection method with the negative value of the angle (in radians) and the necessary distance.

Thank you a-subbotin for introducing me IConstructPoint.
Well, I used it based on ArcObjects' Help but result point was not correct. I used IConstructPoint.ConstructAngleDistance but result X,Y is so large numbers! My X,Ys are longtitude,latitude and distance is meter. Do you know ConstructAngleDistance's unit?
Thanks
0 Kudos
AlexeySubbotin
New Contributor III
Thank you a-subbotin for introducing me IConstructPoint.
Well, I used it based on ArcObjects' Help but result point was not correct. I used IConstructPoint.ConstructAngleDistance but result X,Y is so large numbers! My X,Ys are longtitude,latitude and distance is meter. Do you know ConstructAngleDistance's unit?
Thanks


It's a map unit. So if the map's SpatialReference is IGeographicSpatialReference it should be degrees. The large numbers can represent the values of lon, lat in the IProjectedSpatialReference. Check up the spatial reference of your map to be sure in the results you obtained.
0 Kudos
T__WayneWhitley
Frequent Contributor
Something worth mentioning here - useful for me in 'recomputing' DDP orientation polygons after reorienting a number of the index polys: the Minimum Bounding Geometry (MBG) tool which comes standard (for all licenses) in the Features toolset of the Data Management toolbox.

...will work on 2 point sets as in your case, if you define an ID field.  If you check the box for 'Add geometry characteristics as attributes...' then you'll have a field added that is essentially what you can easily derive azimuth from:  MBG_Orientation

Interesting tool, because I thought it would fail with 2-point sets - instead in my test, a 'zero' width (MBG_Width = 0) polygon was constructed.  The orientation was correctly calculated in polar coordinates (clockwise from the positive X axis)...so I think that's your ticket.  (If you want the measure from the North axis, subtract 90 degrees.)

Hope that helps,
Wayne
0 Kudos
oyleiste
Occasional Contributor
to a-subbotin:
Sorry, I didn't get what to do. How can I make ConstructAngleDistance function to use longtitude, latitude and meter? Can you please explain more or give me example code?
Thank you

to Wayne_Whitley:
Thank you for your reply.
Unfortunately I can't use toolboxes. I should implement it using .NET code. If you could help me on ConstructAngleDistance, that would be great.
Actually I subtract 90 degrees; as you see:
angle = 90 - angle;

but I don't get correct angle.
Thanks
0 Kudos
AlexeySubbotin
New Contributor III
to a-subbotin:
Sorry, I didn't get what to do. How can I make ConstructAngleDistance function to use longtitude, latitude and meter? Can you please explain more or give me example code?
Thank you

to Wayne_Whitley:
Thank you for your reply.
Unfortunately I can't use toolboxes. I should implement it using .NET code. If you could help me on ConstructAngleDistance, that would be great.
Actually I subtract 90 degrees; as you see:
angle = 90 - angle;

but I don't get correct angle.
Thanks


Ok, Oyle.
1. What kind of the application are you developing? Is it a standalone application or it is executed in the ArcGIS application (ArcMap, ArcGlobe etc.)? If it's a standalone application you can use any spatial reference with it. If it's executed in the ArcGIS you should remember that the spatial reference of the app's map will be used in the processing as it specifies the distance units and the angular units. By default the polar angles are used in ArcGIS.
2. All of the geometries you process do not have the assigned spatial reference. It should be assigned to prevent unexpected results of calculations.
3. As i've said earlier, you use the intricate algorithm at all. The angle of the line object can be retrieved through it's Angle property value (the angle in radians between the line and the positive x-axis). The length can be retrieved in the same way through it's  Length property value.
But all you need is to obtain a new point with necessary coordinates through the call of the IConstructPoint.ConstructDeflection method with the angle and the distance. The value of the distance parameter is the length of the line. The value of the angle parameter should be the angle in radians i.e. 30*Math.PI/18
0 Kudos