Calculate Angle Between Two Points JavaScript

random

Calculate Angle Between Two Points JavaScript

Find angle between two points javascript

In this blog post I will share angle between two points formula in JavaScript. Let say we have two latitude and longitude points and need to get angle between 2 points. Find the javascript code snippet below :- 

how to calculate, angle of line,between two points,latitude and longitude
calculate angle between 2 points
<script type="text/javascript">         
            function CalculateAngle() {
           
                var latA='28.998532'; var lngA='77.705612'; //Point A
                var latB='28.685166'; var lngB='77.453613'; //Point B            
             
                var e = Math, ra = e.PI / 180; deg = 180 / e.PI;    
                var x = lngB - lngA;
                var y = lngB - lngA;

                var f = 0;
               
                if (x >= 0 && y >= 0) {
                    y = y * ra; x = x * ra;
                    f = 90 - e.atan(y / x) * deg;
                   
                } else if (x >= 0 && y <= 0) {
                    y = y * ra; x = x * ra;
                    f = 90 + e.abs(e.atan(y / x) * deg);
                   
                } else if (x <= 0 && y <= 0) {
                    y = y * ra; x = x * ra;
                    f = 270 - e.atan(y / x) * deg;
                   
                } else if (x <= 0 && y >= 0) {
                    y = y * ra; x = x * ra;
                    f = 270 + e.abs(e.atan(y / x) * deg);
                }       
                alert("Angle :" + f + " degree" );
            }           
    </script>

Calculate Angle Between Two Points JavaScript Reviewed by Ravi Kumar on 11:28 AM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.