Tall entre dues rectes.
Sistemas de Información
Geográfica
SIG (o GIS)
Curso Master FPC
Pérez Vidal
Sección de Informática Gráfica.
LSI. UPC.
Punto-punto. GIS – p.1/10
Corte entre dos rectas.
x
u 1v 1
x y
2 2
x iyi
x1y1
u2v2
y
Figure 1: Corte entre dos rectas.
Punto-punto. GIS – p.2/10
Fórmulas I
Ecuación de la recta.
y := a + b ∗ x
Dados dos puntos de la recta (x1 , y1 ) y (x2 , y2 ),
se calcula b de esta manera:
b := (y1 − y2 )/(x1 − x2 )
y luego
a := y1 − b ∗ x1
Punto-punto. GIS – p.3/10
Casos particulares I.
x
x y
2 2
x y
1 1
y
Figure 2: Recta vertical.
Punto-punto. GIS – p.4/10
Casos particulares II.
x
x2y2
x1y1
u2v2
u1v1
y
Figure 3: Rectas parelelas.
Punto-punto. GIS – p.5/10
Algoritmo (I.1)
algoritmo corte de rectas
var
x1, y1, x2, y2, u1, v1, u2, v2 : real
xi, yi, a1, a2, b1, b2 : real
sitall, yasta : booleano
fvar
yasta := F ALSO
x1 := LeerReal();
x2 := LeerReal();
u1 := LeerReal();
u2 := LeerReal();
y1 := LeerReal()
y2 := LeerReal()
v1 := LeerReal()
v2 := LeerReal()
Punto-punto. GIS – p.6/10
Algoritmo (I.2)
si(x1 6= x2) −→
b1 := (y2 − y1)/(x2 − x1)
si(u1 6= u2) −→
b2 := (v2 − v1)/(u2 − u1)
a1 := y1 − b1 ∗ x1
a2 := y2 − b2 ∗ x2
si(b1 = b2) −→
EscribirCadena(“NO se cortan”)
yasta := CIERT O
Punto-punto. GIS – p.7/10
Algoritmo (I.3)
sino(¬(b1 = b2)) −→
xi := −(a1 − a2)/(b1 − b2)
yi := a1 + b1 ∗ xi
fsi
sino((u1 = u2)) −→
xi := u1
a1 := y1 − b1 ∗ x1
yi := a1 + b1 ∗ xi
fsi
Punto-punto. GIS – p.8/10
Algoritmo (I.4)
sino((x1 = x2)) −→
xi := x1
si(u1 6= u2) −→
b2 := (v2 − v1)/(u2 − u1)
a2 := v1 − b2 ∗ u1
yi := a2 + b2 ∗ xi
sino((u1 = u2)) −→
EscribirCadena(“NO se cortan”)
yasta := CIERT O
fsi
fsi
Punto-punto. GIS – p.9/10
Algoritmo (I.5)
sitall := ((x1 − xi) ∗ (xi − x2)) >= 0 ∧
(u1 − xi) ∗ (xi − u2)) >= 0 ∧
(y1 − yi) ∗ (yi − y2)) >= 0 ∧
(v1 − yi) ∗ (yi − v2)) >= 0)
si(sitall ∧ ¬yasta) −→
EscribirCadena(“Se cortan en”)
EscribirP T 3D(xi, yi)
t (¬((sitall ∧ (¬yasta()) −→
u
EscribirCadena(“NO se cortan”)
fsi
falgoritmo
Punto-punto. GIS – p.10/10