SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- class Ray{
- constructor(a,b){
- this.A = a;
- this.B = b;
- this.Slope = (this.B.Y - this.A.Y)/(this.B.Y-this.A.Y);
- this.Intercept = this.B.Y - this.Slope*this.B.Y
- }
- Intersects(ray){
- let x = (ray.Intercept - this.Intercept) / (this.Slope - ray.Slope);
- let y = this.Slope*x + this.Intercept;
- // Check Y value for THIS Ray
- let xR = new Engine.DirectedRange(this.A.Y,this.B.Y);
- let xPct = xR.Percent(x);
- if(xPct < 0 || xPct > 1){
- return false;
- }
- // Check Y value for OTHER Ray
- xR = new Engine.DirectedRange(ray.A.Y,ray.B.Y);
- xPct = xR.Percent(x);
- if(xPct < 0 || xPct > 1){
- return false;
- }
- // Check Y value for THIS Ray
- let yR = new Engine.DirectedRange(this.A.Y,this.B.Y);
- let yPct = yR.Percent(y);
- if(yPct < 0 || yPct > 1){
- return false;
- }
- // Check Y value for OTHER Ray
- yR = new Engine.DirectedRange(ray.A.Y,ray.B.Y);
- yPct = yR.Percent(y);
- if(yPct < 0 || yPct > 1){
- return false;
- }
- return true;
- }
- }
RAW Paste Data

