Microstation - Elemento incluido en un poligono

 
Vista:

Elemento incluido en un poligono

Publicado por MaxZ (11 intervenciones) el 21/01/2003 22:15:28
Hay alguna forma de saber a travez de macros si un elemento (punto) o determinadas coordenadas x,y están incluidas en un poligono, ya sea forma poligonal o forma poligonal compleja?

Muchas gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Elemento incluido en un poligono

Publicado por carlos (29 intervenciones) el 22/01/2003 18:20:35
A hi va una función en basic de un tal G.Houck.No se si va a entrar aqui,tampoco se si funciona correctamente.' Hay que definir estas constantes
''Const OUTPOLY = 0% ' point is outside the polygon
' Const INPOLY = 1% ' point is inside the polygon
' Const ONPOLY = 2% ' point is on the polygon border or vertex
' Const C180 = -0.99999999999# ' approximation of cos(180)
' ------------------------------------------------------------------------
Function pointInPoly ( testPt as MBEPoint, polyPts() as MBEPoint, nPolyPts as long, epsilon as double ) as integer
dim i&, iec&, jj&, x_delta&, y_delta&
dim tsc#, tcc#, sc#, cc#, x1#, y1#, x2#, y2#
dim r1#, r2#, ct#, st#, vpl#
iec = 0
tsc = 0.0
sc = 0.0
tcc = 1.0
cc = 1.0
jj = nPolyPts
' calculate delta-x and delta-y
x_delta = polyPts(jj).x - testPt.x
y_delta = polyPts(jj).y - testPt.y
if abs(x_delta) <= epsilon then
if abs(y_delta) <= epsilon then
pointInPoly = ONPOLY
Exit Function
end if
end if
x1 = x_delta
y1 = y_delta
' calculate distance-squared to last point
r1 = (x1 * x1) + (y1 * y1)
' pt on top of vertex ?
if r1 <= epsilon then
pointInPoly = ONPOLY
Exit Function
end if
' cycle thru each boundary point, calculating
' distance to given pt for initial comparison
for i=1 to nPolyPts
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

lo sabia

Publicado por carlos (29 intervenciones) el 22/01/2003 18:26:22
Efectivamente no ha cabido,continuacion...
x_delta = polyPts(i).x - testPt.x
y_delta = polyPts(i).y - testPt.y
if abs(x_delta) <= epsilon then
if abs(y_delta) <= epsilon then
pointInPoly = ONPOLY
Exit Function
end if
end if
x2 = x_delta
y2 = y_delta
r2 = (x2 * x2) + (y2 * y2)
' pt on top of vertex ?
if r2 <= epsilon then
pointInPoly = ONPOLY
Exit Function
end if
vpl = 1.0 / sqr( r1*r2 )
ct = (x1 * x2 + y1 * y2) * vpl
' pt lie on boundary ?
if ct <= C180 then
pointInPoly = ONPOLY
Exit Function
end if
' pt inside or outside boundary ?
if i >= nPolyPts then
if (iec mod 2) = 1 then
pointInPoly = INPOLY
Exit Function
else
pointInPoly = OUTPOLY
Exit Function
end if
end if
' calculate cross-products
st = (x1 * y2 - x2 * y1) * vpl
tsc = sc * ct + cc * st
tcc = cc * ct - sc * st
if tsc*sc <= 0.0 then
if tsc*st < 0.0 then
iec = iec + 1
end if
end if
' set "last" values
sc = tsc
cc = tcc
x1 = x2
y1 = y2
r1 = r2
next i
pointInPoly = OUTPOLY
Exit Function
end function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Muchas Gracias

Publicado por MaxZ (11 intervenciones) el 22/01/2003 19:37:12
Una vez más gracias Carlos, lo probaré y te aviso que pasó
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar