@Test public void intersectionRay() throws Exception { aStart = GeometryFactory.createVector(0,0); aDirection = GeometryFactory.createVector(1,0); a = GeometryFactory.createRay2D(aStart, aDirection); bStart = GeometryFactory.createVector(5,0); bDirection = GeometryFactory.createVector(1,0); b = GeometryFactory.createRay2D(bStart, bDirection); Ray2D intersectionRay = a.intersectionRay(b); assertTrue(intersectionRay.equals(b)); intersectionRay = b.intersectionRay(a); assertTrue(intersectionRay.equals(b)); aStart = GeometryFactory.createVector(0,0); aDirection = GeometryFactory.createVector(0,5); a = GeometryFactory.createRay2D(aStart, aDirection); bStart = GeometryFactory.createVector(0,3); bDirection = GeometryFactory.createVector(0,0.1); b = GeometryFactory.createRay2D(bStart, bDirection); intersectionRay = a.intersectionRay(b); assertTrue(intersectionRay.equals(b)); intersectionRay = b.intersectionRay(a); assertTrue(intersectionRay.equals(b)); aStart = GeometryFactory.createVector(0,0); aDirection = GeometryFactory.createVector(1,0); a = GeometryFactory.createRay2D(aStart, aDirection); bStart = GeometryFactory.createVector(5,0); bDirection = GeometryFactory.createVector(-1,0); b = GeometryFactory.createRay2D(bStart, bDirection); assertNull(a.intersectionRay(b)); aStart = GeometryFactory.createVector(0,0); aDirection = GeometryFactory.createVector(1,0); a = GeometryFactory.createRay2D(aStart, aDirection); bStart = GeometryFactory.createVector(0,5); bDirection = GeometryFactory.createVector(0,-1); b = GeometryFactory.createRay2D(bStart, bDirection); assertNull(a.intersectionRay(b)); }
public Ray2D intersectionRay(Ray2D other) { double dotProduct = this.getDirection().getNormalized().dot(other.getDirection().getNormalized()); if(this.contains(other.getStart()) && !other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(other.getStart(), other.getDirection()); } else if(!this.contains(other.getStart()) && other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(this.getStart(), this.getDirection()); } else { return null; } }
Ray2D { public Ray2D intersectionRay(Ray2D other) { double dotProduct = this.getDirection().getNormalized().dot(other.getDirection().getNormalized()); if(this.contains(other.getStart()) && !other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(other.getStart(), other.getDirection()); } else if(!this.contains(other.getStart()) && other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(this.getStart(), this.getDirection()); } else { return null; } } }
Ray2D { public Ray2D intersectionRay(Ray2D other) { double dotProduct = this.getDirection().getNormalized().dot(other.getDirection().getNormalized()); if(this.contains(other.getStart()) && !other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(other.getStart(), other.getDirection()); } else if(!this.contains(other.getStart()) && other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(this.getStart(), this.getDirection()); } else { return null; } } Ray2D(Vector2D start, Vector2D direction); }
Ray2D { public Ray2D intersectionRay(Ray2D other) { double dotProduct = this.getDirection().getNormalized().dot(other.getDirection().getNormalized()); if(this.contains(other.getStart()) && !other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(other.getStart(), other.getDirection()); } else if(!this.contains(other.getStart()) && other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(this.getStart(), this.getDirection()); } else { return null; } } Ray2D(Vector2D start, Vector2D direction); Vector2D getStart(); void setStart(Vector2D start); Vector2D getDirection(); void setDirection(Vector2D direction); Vector2D intersectionPoint(Ray2D other); Ray2D intersectionRay(Ray2D other); Segment2D intersectionSegment(Ray2D other); boolean contains(Vector2D point); boolean isParallel(Ray2D other); boolean equals(Ray2D other); String toString(); }
Ray2D { public Ray2D intersectionRay(Ray2D other) { double dotProduct = this.getDirection().getNormalized().dot(other.getDirection().getNormalized()); if(this.contains(other.getStart()) && !other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(other.getStart(), other.getDirection()); } else if(!this.contains(other.getStart()) && other.contains(this.getStart()) && Math.abs(1.0 - dotProduct) < EPSILON) { return new Ray2D(this.getStart(), this.getDirection()); } else { return null; } } Ray2D(Vector2D start, Vector2D direction); Vector2D getStart(); void setStart(Vector2D start); Vector2D getDirection(); void setDirection(Vector2D direction); Vector2D intersectionPoint(Ray2D other); Ray2D intersectionRay(Ray2D other); Segment2D intersectionSegment(Ray2D other); boolean contains(Vector2D point); boolean isParallel(Ray2D other); boolean equals(Ray2D other); String toString();  }