Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Langages serveur > ASP
ASP Forum sur la programmation ASP. Avant de poster : Cours ASP, FAQ ASP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 02/05/2007, 09h50   #1
Invité de passage
 
Inscription : mai 2006
Messages : 11
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 11
Points : 2
Points : 2
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 ?
titelisette est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/05/2007, 11h44   #2
Inactif
 
Inscription : mars 2002
Messages : 1 295
Détails du profil
Informations personnelles :
Âge : 41

Informations forums :
Inscription : mars 2002
Messages : 1 295
Points : 1 345
Points : 1 345
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.
Florian est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/05/2007, 12h16   #3
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
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.

Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/05/2007, 09h02   #4
Invité de passage
 
Inscription : mai 2006
Messages : 11
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 11
Points : 2
Points : 2
J'ai finalement trouvé la solution
titelisette est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/05/2007, 10h58   #5
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
C'est gentil si tu nous en fais part.

Merci
Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/05/2007, 11h14   #6
Invité de passage
 
Inscription : mai 2006
Messages : 11
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 11
Points : 2
Points : 2
pt correspond aux coordonnées du point (x,y)
poly2 correspond aux coordonnées du polygone (x,y,x1,y1,x2,y2,...)

Code :
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
titelisette est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/05/2007, 14h01   #7
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
mmmh sauf que
Code :
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.
Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/05/2007, 17h08   #8
Invité de passage
 
Inscription : mai 2006
Messages : 11
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 11
Points : 2
Points : 2
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 :
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 ?
titelisette est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h25.


 
 
 
 
Partenaires

Hébergement Web