Mercurial > dive4elements > river
diff backend/src/main/java/org/dive4elements/river/importer/parsers/tim/Line.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-backend/src/main/java/org/dive4elements/river/importer/parsers/tim/Line.java@18619c1e7c2a |
children | 4dd33b86dc61 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/tim/Line.java Thu Apr 25 15:23:37 2013 +0200 @@ -0,0 +1,34 @@ +package org.dive4elements.river.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 :