Infrastructure Map Server Forum
Welcome to Autodesk’s Infrastructure Map Server Forums. Share your knowledge, ask questions, and explore popular Infrastructure Map Server topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calculate the Angle Between 2 points

2 REPLIES 2
Reply
Message 1 of 3
jacklloyd
210 Views, 2 Replies

Calculate the Angle Between 2 points

Is it possible to calculate the angle between 2 points? I haven't found anything in the API that will give me the angle of a polyline I select in the viewer, but I can get the vertices for the start and end points of the feature. What I need to be able to do is get the angle between those 2 points. I have searched for solutions using javascript and have found the atan2() function that might work, but it looks pretty complicated. Any suggestions?

Jack
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: jacklloyd

Jack,

That's probably going to be the easiest way. 
Here's some sample code that works.  Note that the trigonometric functions
in JavaScript returns angles in radians, hence the conversion to
degrees:

 

var x1=0;
var x2=45;
var y1=0;
var
y2=45;
var pi = Math.PI;
var angleRad=Math.atan((y2-y1)/(x2-x1));
var
angleDeg=angleRad*(180/pi);
alert(angleRad);
alert(angleDeg);
 

 

You'll also have to do some checking in the code
for the orientation of the line so that the proper angle is
calculated.

 


--
Andy Morsell, P.E.
Spatial
Integrators, Inc.

href="http://www.spatialgis.com">http://www.spatialgis.com


 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Is
it possible to calculate the angle between 2 points? I haven't found anything
in the API that will give me the angle of a polyline I select in the viewer,
but I can get the vertices for the start and end points of the feature. What I
need to be able to do is get the angle between those 2 points. I have searched
for solutions using javascript and have found the atan2() function that might
work, but it looks pretty complicated. Any suggestions?

Jack

Message 3 of 3
jacklloyd
in reply to: jacklloyd

Andy,

Your the man! I plugged this in, changed the variable names to the ones I already had, added the code for angle orientation and viola! Thanks again.

Jack

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report