Mercurial > dive4elements > river
diff flys-backend/src/main/java/org/dive4elements/river/importer/parsers/tim/Line.java @ 5828:dfb26b03b179
Moved directories to org.dive4elements.river
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:53:11 +0200 |
parents | flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/Line.java@ce6b9945bf8e |
children | 18619c1e7c2a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/org/dive4elements/river/importer/parsers/tim/Line.java Thu Apr 25 11:53:11 2013 +0200 @@ -0,0 +1,34 @@ +package de.intevation.flys.importer.parsers.tim; + +/** Two coordinates and a helper. */ +public class Line { + + public Coordinate a; + public Coordinate b; + + public Line() { + } + + public Line(Coordinate a, Coordinate b) { + this.a = a; + this.b = b; + } + + /** Project coordinate to line. */ + public double distanceToFirst(Coordinate c) { + + double nx = b.x - a.x; + double ny = b.y - a.y; + + double len = Math.sqrt(nx*nx + ny*ny); + + nx /= len; + ny /= len; + + double px = c.x - a.x; + double py = c.y - a.y; + + return nx*px + ny*py; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :