Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/XY.java @ 5083:7bbee0cfc171 slt-simplify-cross-sections
Added experimental Douglas Peuker simplification of cross sections.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 24 Feb 2013 17:29:52 +0100 |
parents | 2b0426b79a92 |
children |
comparison
equal
deleted
inserted
replaced
5082:fb4d87274f28 | 5083:7bbee0cfc171 |
---|---|
10 protected double x; | 10 protected double x; |
11 protected double y; | 11 protected double y; |
12 protected int index; | 12 protected int index; |
13 | 13 |
14 public XY() { | 14 public XY() { |
15 } | |
16 | |
17 public XY(XY other) { | |
18 this(other.x, other.y, other.index); | |
15 } | 19 } |
16 | 20 |
17 public XY(double x, double y, int index) { | 21 public XY(double x, double y, int index) { |
18 this.x = x; | 22 this.x = x; |
19 this.y = y; | 23 this.y = y; |
50 } | 54 } |
51 | 55 |
52 public void setIndex(int index) { | 56 public void setIndex(int index) { |
53 this.index = index; | 57 this.index = index; |
54 } | 58 } |
59 | |
60 public double dot(double ox, double oy) { | |
61 return x*ox + y*oy; | |
62 } | |
63 | |
64 public double dot(XY other) { | |
65 return dot(other.x, other.y); | |
66 } | |
67 | |
68 public XY sub(XY other) { | |
69 x -= other.x; | |
70 y -= other.y; | |
71 return this; | |
72 } | |
73 | |
74 public XY ortho() { | |
75 double z = x; | |
76 x = y; | |
77 y = -z; | |
78 return this; | |
79 } | |
80 | |
81 public XY normalize() { | |
82 double len = dot(this); | |
83 | |
84 if (len > 1e-6) { | |
85 len = 1d/Math.sqrt(len); | |
86 x *= len; | |
87 y *= len; | |
88 } | |
89 | |
90 return this; | |
91 } | |
92 | |
93 // x*nx + y*ny + d = 0 <=> d = -x*nx -y*ny | |
94 public double lineOffset(XY p) { | |
95 return -x*p.x -y*p.y; | |
96 } | |
55 } | 97 } |
56 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 98 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |