Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

99
Vistas
If a point in lng and lat is on line Segment or it only 2 meters away

Here is what I am trying to achieve,( please do not put duplicate has I cannot ask questions),I want to find if the point cLng, cLat is on the Segment line aLng,alat to bLng,bLng. My problem is that my distance check is not working at 2.00 meters which is EPSILON. Any help in improving this code would be much appreciated.

        var crossProduct = (cLat - aLat) * (bLng - aLng) - (cLng - aLng) * (bLat - aLat);
        if (Math.Abs(crossProduct) == 0)
        {
            return true;
        }
        
        var dotProduct = (cLng - aLng) * (bLng - aLng) + (cLat - aLat) * (bLat - aLat);

        var squaredLength = (bLng - aLng) * (bLng - aLng) + (bLat - aLat) * (bLat - aLat);
        

        var param = -1d;
        if (squaredLength != 0) //in case of 0 length line
        {
            param = dotProduct / squaredLength;
        }

        double xx = param < 0 ? aLng : param >  1 ? bLng: aLng + param * bLng - aLng;
        double yy = param < 0 ? aLat : param >  1 ? bLat: aLat + param * bLat - aLat; 
        var dx = cLng - xx;
        var dy = cLat - yy;
        var sqrt = Math.Sqrt(dx * dx + dy * dy);
        return sqrt < EPSILON;
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda