10514 - River Crossing
Moderator: Board moderators
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
10514 - River Crossing
Can someone tell me the intermediate distances between the polygons and rivers? I think my distance function is off a bit..
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Call the distance between an edge E and a vertex V[j] Dist(E,V[j]), where E and V[j] don't necessarily belong to the same polygon.
Then the distance between a polygon P[k] and a vertex V[j] is:
Dist(P[k],V[j]) = Min{over all E of P[k]}(Dist(P[k].E,V[j]))
Then the distance between two polygons P[k] and P[k'], with vertices P[k].V[j] and P[k'].V[j'] resp. is:
Dist(P[k],P[k']) = Min(Min{over all V[j] of P[k]}(Dist(P[k'],P[k].V[j])),Min{over all V[j'] of P[k']}(Dist(P[k],P[k'].V[j'])))
I'll bet you can work out Dist(E,V[j]) yourself
The two riverbanks (P[1] and P[2]) aren't exacly polygons, but they can be treated similarly.
Now the distance between two polygons P[a] and P can be shortened if there is a third polygon P[c] so that:
Dist(P[a],P[c]) + Dist(P[c],P) < Dist(P[a],P)
You can use a well known algorithm to iterate over all (a,b,c) and ultimately find the shortest distance between P[1] and P[2].
PS. Keep it a secret, cause I think it's a spoiler...
Then the distance between a polygon P[k] and a vertex V[j] is:
Dist(P[k],V[j]) = Min{over all E of P[k]}(Dist(P[k].E,V[j]))
Then the distance between two polygons P[k] and P[k'], with vertices P[k].V[j] and P[k'].V[j'] resp. is:
Dist(P[k],P[k']) = Min(Min{over all V[j] of P[k]}(Dist(P[k'],P[k].V[j])),Min{over all V[j'] of P[k']}(Dist(P[k],P[k'].V[j'])))
I'll bet you can work out Dist(E,V[j]) yourself

The two riverbanks (P[1] and P[2]) aren't exacly polygons, but they can be treated similarly.
Now the distance between two polygons P[a] and P can be shortened if there is a third polygon P[c] so that:
Dist(P[a],P[c]) + Dist(P[c],P) < Dist(P[a],P)
You can use a well known algorithm to iterate over all (a,b,c) and ultimately find the shortest distance between P[1] and P[2].
PS. Keep it a secret, cause I think it's a spoiler...
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
-
- Experienced poster
- Posts: 193
- Joined: Thu Sep 19, 2002 6:39 am
- Location: Indonesia
- Contact:
This is a really nice problem. It looks overwhelming at first ... but when you relax a little bit, ... it actually goes down to "distance between 2 segments" problem.
I got the segment-segment distance from http://www.softsurfer.com ...
-turuthok-
I got the segment-segment distance from http://www.softsurfer.com ...
-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
Hey, should I take that as a compliment or not?
I've done a couple of easier problems lately...
River Crossing I thought very neat because what you maybe at first sight want is distance between two line segments which, of course, reduces to the distance between one line segment and one point. Originally I only had two river banks, but thought it cool with some islands to add an extra (but still simple) element to the problem.

River Crossing I thought very neat because what you maybe at first sight want is distance between two line segments which, of course, reduces to the distance between one line segment and one point. Originally I only had two river banks, but thought it cool with some islands to add an extra (but still simple) element to the problem.