Trying to find out if it is possible to find out angle of a geometry: Rectangle geometry in my case.

Thanks,

Bikesh

Trying to find out if it is possible to find out angle of a geometry: Rectangle geometry in my case.

Thanks,

Bikesh

- 2 people found this helpful
A polygon doesn't really have an "angle". You could make the assumption that if your polygon has 4 vertices, it's a rectangle. Then you need to make an assumption about which vertex is at which index (ie if it's rotated 0 degrees, is index 0 the lower-left vertex?).

Once you do that, you could take two consecutive vertices and use trigonometry to calculate an angle.

So you would end up with something along the lines of this:

MapPoint firstVertex = polygon.Parts[0][0].StartPoint;

MapPoint secondVertex = polygon.Parts[0][0].EndPoint;

double xDiff = secondVertex.X - firstVertex.X;

double yDiff = secondVertex.Y - firstVertex.Y;

double angle = Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI;

A polygon doesn't really have an "angle". You could make the assumption that if your polygon has 4 vertices, it's a rectangle. Then you need to make an assumption about which vertex is at which index (ie if it's rotated 0 degrees, is index 0 the lower-left vertex?).

Once you do that, you could take two consecutive vertices and use trigonometry to calculate an angle.

So you would end up with something along the lines of this:

MapPoint firstVertex = polygon.Parts[0][0].StartPoint;

MapPoint secondVertex = polygon.Parts[0][0].EndPoint;

double xDiff = secondVertex.X - firstVertex.X;

double yDiff = secondVertex.Y - firstVertex.Y;

double angle = Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI;