IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP Discussion :

Point dans un polygone


Sujet :

ASP

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 11
    Points : 7
    Points
    7
    Par défaut Point dans un polygone
    Bonjour,

    pour un projet, je dois dire si un point (x,y) est dans un polygone. Sachant que les coordonnées de mon polygone sont stockées de cette façon (x1,y1;x2,y2,...) dans une base de données

    Quelqu'un aurait-il une idée pour réaliser cela en asp ?

  2. #2
    Invité
    Invité(e)
    Par défaut
    Ca manque cruellement de détails.
    Tu as déjà la base de données ? tu as besoin de l'algo mathématique pour résoudre ton problème ?
    Il faudrait une expression de besoins détaillée.

  3. #3
    Expert éminent
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Points : 9 506
    Points
    9 506
    Par défaut
    Amusant comme casse tête.

    Bon, on supposera que tu sais déjà récupérer x et y.
    Ensuite, il s'agit simplement de vérifier successivement plusieurs inéquations à plusieurs inconnues du genre y >= 2x + 3.
    Toute la difficulté est là car il faut encore que tu determines les inéquations en fonction des coordonnées des angles de ton polygone.

    "Winter is coming" (ma nouvelle page d'accueil)

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 11
    Points : 7
    Points
    7
    Par défaut
    J'ai finalement trouvé la solution

  5. #5
    Expert éminent
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Points : 9 506
    Points
    9 506
    Par défaut
    C'est gentil si tu nous en fais part.

    Merci
    "Winter is coming" (ma nouvelle page d'accueil)

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 11
    Points : 7
    Points
    7
    Par défaut
    pt correspond aux coordonnées du point (x,y)
    poly2 correspond aux coordonnées du polygone (x,y,x1,y1,x2,y2,...)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    function inPoly(pt, poly2)
    	Dim coord, coordPt
    	coord =poly2
       	coordPt =pt
     
      	poly =split(coord,",",-1,1)
    	monPoint =split(coordPt,",",-1,1)
     
         Dim npoints
    	 npoints=Ubound(poly)
        Dim xnew,ynew,xold,yold,x1,y1,x2,y2,i
         Dim inside
    	 inside=false
     
         if (npoints/2 < 3) then
               inPoly = 1
    		 end if
     
    	 xold=poly(npoints-2)
         yold=poly(npoints-1)
     
         for i=0 to npoints  
              xnew=poly(i)
              ynew=poly(i+1)
              if  xnew > xold then 
                   x1=xold
                   x2=xnew
                   y1=yold
                   y2=ynew
     
              else
                   x1=xnew
                   x2=xold
                   y1=ynew
                   y2=yold
             end if
              if ((xnew < monPoint(0)) = (monPoint(0) <= xold) and ((monPoint(1)-y1)*(x2-x1) < (y2-y1)*(monPoint(0)-x1))) then
                  inPoly = true
    			   else
    			   inPoly = false
              end if
              xold=xnew
              yold=ynew
    		  i=i+2
         next
     
    end function

  7. #7
    Expert éminent
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Points : 9 506
    Points
    9 506
    Par défaut
    mmmh sauf que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    response.Write(inpoly("3,3", "3,3,4,4,3,4"))
    renvoit "faux". Comment doivent s'enchainer les coordonnées?
    De plus, tu ne peux avoir que des coordonnées entières.
    "Winter is coming" (ma nouvelle page d'accueil)

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 11
    Points : 7
    Points
    7
    Par défaut
    Voila ce que j'avais trouvé en javascript que j'ai adapté...

    Dans cette exemple le fait que le point soit sur une coordonnée du polygone ça marche..

    Je me suis certainement trompé en l'adaptant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
     
    /* inPoly()
    Finds if a given point is within a polygon.
     
    Based on Bob Stein's inpoly() function for C.
    <a href="http://home.earthlink.net/~bobstein/inpoly/" target="_blank">http://home.earthlink.net/~bobstein/inpoly/</a>
     
    Modified for JavaScript by Scott Andrew LePera.
     
    Parameters:
    poly: array containing x/y coordinate pairs that
      describe the vertices of the polygon. Format is
      indentical to that of HTML image maps, i.e. [x1,y1,x2,y2,...]
      
    px: the x-coordinate of the target point.
     
    py: the y-coordinate of the target point.
     
    Return value:
    true if the point is within the polygon, false if not.
    */
     
    function inPoly(poly,px,py)
    {
         var npoints = poly.length; // number of points in polygon
         var xnew,ynew,xold,yold,x1,y1,x2,y2,i;
         var inside=false;
     
         if (npoints/2 < 3) { // points don't describe a polygon
              return false;
         }
         xold=poly[npoints-2];
         yold=poly[npoints-1];
     
         for (i=0 ; i < npoints ; i=i+2) {
              xnew=poly[i];
              ynew=poly[i+1];
              if (xnew > xold) {
                   x1=xold;
                   x2=xnew;
                   y1=yold;
                   y2=ynew;
              }
              else {
                   x1=xnew;
                   x2=xold;
                   y1=ynew;
                   y2=yold;
              }
              if ((xnew < px) == (px <= xold) && ((py-y1)*(x2-x1) < (y2-y1)*(px-x1))) {
                   inside=!inside;
              }
              xold=xnew;
              yold=ynew;
         }
         return inside;
    }
    Peut-être que qqun peut résoudre mon problème ?

Discussions similaires

  1. [C] présence d'un point dans un polygone
    Par adiiii dans le forum Développement 2D, 3D et Jeux
    Réponses: 15
    Dernier message: 16/11/2019, 09h14
  2. Nombre maximum de point dans un polygon type geography
    Par blairswish dans le forum MS SQL Server
    Réponses: 10
    Dernier message: 13/07/2010, 14h18
  3. Point dans un polygone 3D
    Par silfride dans le forum Algorithmes et structures de données
    Réponses: 11
    Dernier message: 22/08/2008, 11h04
  4. Point dans un polygone
    Par kerinel dans le forum Mathématiques
    Réponses: 5
    Dernier message: 17/10/2007, 12h23
  5. Point dans un polygone
    Par titelisette dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 27/04/2007, 11h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo