- Sep 29, 2004
- 18,656
- 67
- 91
http://commons.apache.org/proper/co....commons.math3.geometry.euclidean.threed.Line)
Can someone explain to me why this does not return a point object and how I am supposed to used a Vector?
Class Line :: public Vector3D intersection(Line line)
Get the intersection point of the instance and another line.
Parameters:line - other lineReturns:intersection point of the instance and the other line or null if there are no intersection points
As I look more, a bunch of methods say they return a Point but return a Vector.
Can someone explain to me why this does not return a point object and how I am supposed to used a Vector?
Class Line :: public Vector3D intersection(Line line)
Get the intersection point of the instance and another line.
Parameters:line - other lineReturns:intersection point of the instance and the other line or null if there are no intersection points
Code:
258 /** Get the intersection point of the instance and another line.
259 * @param line other line
260 * @return intersection point of the instance and the other line
261 * or null if there are no intersection points
262 */
263 public Vector3D intersection(final Line line) {
264 final Vector3D closest = closestPoint(line);
265 return line.contains(closest) ? closest : null;
266 }
241 public Vector3D closestPoint(final Line line) {
242
243 final double cos = direction.dotProduct(line.direction);
244 final double n = 1 - cos * cos;
245 if (n < Precision.EPSILON) {
246 // the lines are parallel
247 return zero;
248 }
249
250 final Vector3D delta0 = line.zero.subtract(zero);
251 final double a = delta0.dotProduct(direction);
252 final double b = delta0.dotProduct(line.direction);
253
254 return new Vector3D(1, zero, (a - b * cos) / n, direction);
255
256 }
049 /** Line point closest to the origin. */
050 private Vector3D zero;
As I look more, a bunch of methods say they return a Point but return a Vector.
Last edited: