07.04.2015 Views

Hausdorff distance between two polygons in 2D Jarek Rossignac ...

Hausdorff distance between two polygons in 2D Jarek Rossignac ...

Hausdorff distance between two polygons in 2D Jarek Rossignac ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Hausdorff</strong> <strong>distance</strong> <strong>between</strong> <strong>two</strong> <strong>polygons</strong> <strong>in</strong> <strong>2D</strong><br />

<strong>Jarek</strong> <strong>Rossignac</strong><br />

Proc Onto(s,a,b) {RETURN((ab•as>0)==(ba•bs>0))}; # s projects onto segment (a.b)<br />

Proc n(j) {RETURN((j+1) mod t)} # next vertex: t = total number of vertices <strong>in</strong> polygon<br />

Proc M2(s,P) {<br />

# m<strong>in</strong>imum square <strong>distance</strong> from s to polygon P<br />

d:=(sP 0 ) 2 ;<br />

# <strong>in</strong>it d to square of <strong>distance</strong> to vertex 0 of P<br />

FOR j:=1 to |P| DO {<br />

# for all edges of P<br />

IF Onto(s,P j ,P k )<br />

# case where I am on edge<br />

THEN dd:=(P j P n(j) ¥P j s) 2 /(P j P n(j) ) # po<strong>in</strong>t-l<strong>in</strong>e <strong>distance</strong>.<br />

ELSE dd:=(P j s) 2 ;<br />

# case where I am on vertex<br />

IF ddd THEN d:=dd;}<br />

RETURN(d)}<br />

Proc H2(A,B) {<br />

RETURN(max(D2(A,B), D2(A,B));<br />

# Maximum deviation squared <strong>between</strong> po<strong>in</strong>ts on A and B<br />

# candidates positions on A for her<br />

# <strong>in</strong>it deviation to zero<br />

# for each candidate where she could try to hide<br />

# m<strong>in</strong>imum <strong>distance</strong> square from s to B<br />

# adjust d if found better hid<strong>in</strong>g place for her<br />

# Symmetric <strong>Hausdorff</strong> <strong>distance</strong> <strong>between</strong> A and B<br />

Proc Candidates(A,B) {<br />

# Candidates on A for best hid<strong>in</strong>g places away from B<br />

C:=vertex_set(A);<br />

# start by <strong>in</strong>clud<strong>in</strong>g all vertices of A<br />

FOR j:=1 to |A| DO {<br />

# for each edge A j A j+1 where she may hide<br />

FOR a:=0 TO |B|–1 DO<br />

FOR b:=0 TO |B|–1 DO { # case where Joe and I are on vertices of B<br />

s:=VV(A j ,A n(j) , B a ,B b ); # position for her on edge equidistant from B a and B b<br />

IF onto(s, A j ,A n(j) ) # she is still on her edge<br />

THEN C+={s}}; # add po<strong>in</strong>t s to candidates. Remember it goes with a, b.<br />

FOR a:=0 TO |B|–1 DO<br />

FOR b:=0 TO |B|–1 DO { # case where Joe is at vertex a and I on an edge (b,n(b))<br />

s:=VE(A j ,A n(j) ,B a ,B b , B n(b) ); # position for her on edge equidistant from B a and B b<br />

IF onto(s, A j ,A n(j) ) # she is still on her edge<br />

AND onto (s, B b , B n(b) ) # I am still on my edge<br />

THEN C+={s}}; # add po<strong>in</strong>t s to candidates. Remember it goes with a, b.<br />

FOR a:=0 TO |B|–1 DO<br />

FOR b:=a+1 TO |B|–1 DO { # case where Joe and I are on edges of B<br />

s:=EE(A j ,A n(j) ,B a ,B n(b) ,B b ,B n(b) ); # position for her on edge equidistant from ours<br />

IF onto(s, A j ,A n(j) ) AND onto (s, B a , B n(a) ) AND onto (s, B b , B n(b) ) # all 3 on our edges<br />

THEN C+={s}}} # add po<strong>in</strong>t s to candidates. Remember it goes with a, b.<br />

RETURN(C) }


Proc VV(u,v,a,b)<br />

# returns <strong>in</strong>tersection of l<strong>in</strong>e(u,v) with the bisector of a and b<br />

u<br />

s<br />

v<br />

a<br />

b<br />

Proc VE(u,v,a,b,c)<br />

# returns <strong>in</strong>tersection of l<strong>in</strong>e(u,v) with parabola <strong>between</strong> po<strong>in</strong>t a and l<strong>in</strong>e(b,c)<br />

u<br />

s<br />

c<br />

v<br />

a<br />

b<br />

Proc EE(u,v,a,b,c,d)<br />

# returns <strong>in</strong>tersection of l<strong>in</strong>e through u and v with bisector of the l<strong>in</strong>e(a,b) and l<strong>in</strong>e(c,d)<br />

b<br />

u<br />

a<br />

s<br />

c<br />

d<br />

v

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!