generated from agdturner/ccg-v2d
/
V3D_VLineDouble.java
167 lines (153 loc) · 5.17 KB
/
V3D_VLineDouble.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright 2020 Andy Turner, University of Leeds.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.leeds.ccg.v3d.geometry.d.light;
import java.io.Serializable;
/**
* 3D representation of a moveable finite length line. The line starts at
* {@link #p} and ends at {@link #q}. The "*" denotes a point in 3D and the
* line is shown with a line of "e" symbols in the following depiction: {@code
* z
* y -
* + / * p=<x0,y0,z0>
* | / e
* | / e
* | z0-/ e
* | / e
* | / e
* | / e
* | / e
* y0-| / e
* | / e
* |/ x1 e
* x - ---------------------|-----------/---e---/---- + x
* /| e x0
* / |-y1 e
* / | e
* / | e
* z1-/ | e
* / | e
* / | * q=<x1,y1,z1>
* / |
* / |
* + |
* z -
* y
* }
* <ul>
* <li>Vector Form
* <ul>
* <li>{@code (x,y,z) = (p.getX(oom),p.getY(oom),p.getZ(oom)) + t(v.getDX(oom),v.getDY(oom),v.getDZ(oom))}</li>
* </ul>
* <li>Parametric Form (where t describes a particular point on the line)
* <ul>
* <li>{@code x = p.getX(oom) + t(v.getDX(oom))}</li>
* <li>{@code y = p.getY(oom) + t(v.getDY(oom))}</li>
* <li>{@code z = p.getZ(oom) + t(v.getDZ(oom))}</li>
* </ul>
* <li>Symmetric Form (assume {@code v.getDX(oom)}, {@code v.getDY(oom)}, and
* {@code v.getDZ(oom)} are all nonzero)
* <ul>
* <li>{@code (x−p.getX(oom))/v.getDX(oom) = (y−p.getY(oom))/v.getDY(oom) = (z−p.getZ(oom))/v.getDZ(oom)}</li>
* </ul></li>
* </ul>
*
* @author Andy Turner
* @version 1.0
*/
public class V3D_VLineDouble implements Serializable {
private static final long serialVersionUID = 1L;
/**
* A point defining the line.
*/
public final V3D_VDouble p;
/**
* A point defining the line.
*/
public final V3D_VDouble q;
/**
* @param l Used to initialise this.
*/
public V3D_VLineDouble(V3D_VLineDouble l) {
this.p = new V3D_VDouble(l.p);
this.q = new V3D_VDouble(l.q);
}
/**
* @param p What {@link #p} is set to.
* @param q What {@link #q} is set to.
*/
public V3D_VLineDouble(V3D_VDouble p, V3D_VDouble q) {
this.p = p;
this.q = q;
}
@Override
public String toString() {
return toString("");
}
/**
* @param pad A padding of spaces.
* @return A description of this.
*/
public String toString(String pad) {
return this.getClass().getSimpleName() + "\n"
+ pad + "(\n"
+ toStringFields(pad + " ") + "\n"
+ pad + ")";
}
/**
* @param pad A padding of spaces.
* @return A description of the fields.
*/
protected String toStringFields(String pad) {
return pad + "p=" + p.toString(pad) + "\n"
+ pad + ",\n"
+ pad + "q=" + q.toString(pad);
// + pad + "q=" + q.toString(pad) + "\n"
// + pad + ",\n"
// + pad + "v=" + v.toString(pad);
}
@Override
public boolean equals(Object o) {
if (o instanceof V3D_VLineDouble l) {
return equals(l);
}
return false;
}
@Override
public int hashCode() {
return 0;
}
/**
* The lines are equal irrespective of the direction vector between the
* points.
*
* @param l The line to test if it is the same as {@code this}.
* @return {@code true} iff {@code l} is the same as {@code this}.
*/
public boolean equals(V3D_VLineDouble l) {
return (p.equals(l.p) && q.equals(l.q))
|| (p.equals(l.q) && q.equals(l.p));
}
// @Override
// public V3D_VPoint getC() {
// if (c == null) {
// c = new V3D_VPoint(
// (p.getX().add(q.getX())).divide(2),
// (p.getY().add(q.getY())).divide(2),
// (p.getZ().add(q.getZ())).divide(2));
// }
// return c;
// }
}