Skip to main content

Fencing ( Latitude Longitude )

 Check Lat/Long is Inside/Outside of fencing


<?php

function onLine($side,$point)  //check whether p is on the line or not

{


  if($point['x'] <= max($side['x']['x'], $side['y']['x']) && $point['x'] <= min($side['x']['x'], $side['y']['x']) &&

   ($point['y'] <= max($side['x']['y'], $side['y']['y']) && $point['y'] <= min($side['x']['y'], $side['y']['y'])))

      return true;


return false;

}

function direction($point1,$point2,$point3)

{

   $val=($point2['y']-$point1['y'])*($point3['x']-$point2['x'])-($point2['x']-$point1['x'])*($point3['y']-$point2['y']);

   if ($val == 0)

   return 0; //colinear

   else if($val <0)

   return 2;          //anti-clockwise direction

   return 1;          //clockwise direction


}

function isIntersect($side,$exline)

{


  //four direction for two lines and points of other line

 $dir1 = direction($side['x'], $side['y'], $exline['x']);

 $dir2 = direction($side['x'], $side['y'], $exline['y']);

 $dir3 = direction($exline['x'], $exline['y'], $side['x']);

 $dir4 = direction($exline['x'], $exline['y'], $side['y']);


 if($dir1 != $dir2 && $dir3 != $dir4)

   return true;           //they are intersecting

if($dir1==0 && onLine($side, $exline['x']))        //when p2 of line2 are on the line1

   return true;

if($dir2==0 && onLine($side, $exline['y']))         //when p1 of line2 are on the line1

   return true;

if($dir3==0 && onLine($exline, $side['x']))       //when p2 of line1 are on the line2

   return true;

if($dir4==0 && onLine($exline, $side['y'])) //when p1 of line1 are on the line2

   return true;

return false;


}

function checkInside($polygon,$point,$n)

{

  if($n < 3) //when polygon has less than 3 edge, it is not polygon

   return false;

echo "<pre>";

   $exline=array('x'=>$point,'y'=>array('x'=>999999,'y'=>$point['y']));//create a point at infinity, y is same as point p

   $count=0;

   $i=0;

   do {

     $m=($i+1)%$n;

     $side=array('x'=>$polygon[$i],'y'=>$polygon[$m]);//forming a line from two consecutive points of poly


     if(isIntersect($side,$exline))  //if side is intersects exline

     {

       if(direction($side['x'], $point, $side['y']) == 0)

            return onLine($side, $point);

             $count++;

     }


     $i = ($i+1)%$n;

   }

   while($i != 0);

   return $count&1;


}

$polygon=array(

          array('x'=>0,'y'=>0),

          array('x'=>10,'y'=>0),

          array('x'=>10,'y'=>10),

          array('x'=>0,'y'=>10));

$point=array('x'=>9,

            'y'=>9);

$n=4;

if(checkInside($polygon,$point,$n))

{

echo "User is inside the Polygon";


}

else {

  echo "User is outside the Polygon";

}

?>


Comments

Popular posts from this blog

KrutiDev To Unicode Conversion

http://wrd.bih.nic.in/font_KtoU.htm ___________________________________ <html> <head> <title>KrutiDev <=> Unicode Conversion</title> </title> <link rel="stylesheet" href="style.css">       <script src='script.js'></script> </head> <!--       body of the HTML starts here. one text box is provided each for input and output. --> <body bgcolor='#99CCFF'> <P style='text-align:center; font-family: Arial, Helvetica, sans-serif; font-size: 14pt; font-weight:bold; background-color: #FF6600; color: #FFFFFF'> Conversion between Krutidev-010 and Unicode क्रुतिदेव-०१० और यूनिकोड के बीच रूपांतरण </P> <form name="form1"> <p style='font-size:10pt'>क्रुतिदेव-०१० (Kruti Dev 010) फॉन्ट में टंकिट टेक्स्ट को "क्रुतिदेव-०१०" नामक टेक्स्ट बॉक्स में टाईप या पेस्ट करें तथा इसे यूनिकोड में रूपांतरित करने के लिए अधोमुख तीर वाल...

Array Difference, Radio Button Js,

$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"green","g"=>"blue"); $result=array_diff($a1,$a2); print_r($result); ______________________________________________________ <script type="text/javascript">  $(document).ready(function(){       $("input[type='radio']").click(function(){             var radioValue = $("input[name='duration']:checked").val();             if(radioValue){                 alert("Your are a - " + radioValue);             }         });  }); </script>   $(document).on("click", ".upappdesc", function(){ // alert($(this).data('id'));  var option = $(this).data("cat").split(",");  // alert($(this).data(...

Update Node on Mac and Windows

Using brew: brew update brew upgrade node Using nvm:   NVM (Node Version Manager) is a tool that allows you to manage multiple versions of Node on your system. You can use nvm to install, update, and switch between different versions of Node. To update your version of Node using nvm, do the following: 1. Check if you already have nvm installed on your system:   
nvm --version 2. If it's not installed, install nvm using this command:    
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 3. Once nvm is installed, check your current version of Node by running the following command: 
node -v 4. Then update your version of Node using the following command:   
nvm install node --reinstall-packages-from=node 5. And finally, verify that your update is complete by rechecking your Node version:   
node -v ———————————————————————————————————— Using NPM: To update Node using NPM, do the following: 1. Open the Terminal and check your curren...