daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Ray{
  2.    constructor(a,b){
  3.         this.A = a;
  4.         this.B = b;
  5.         this.Slope = (this.B.Y - this.A.Y)/(this.B.Y-this.A.Y);
  6.         this.Intercept = this.B.Y - this.Slope*this.B.Y
  7.    }
  8.    Intersects(ray){
  9.       let x = (ray.Intercept - this.Intercept) / (this.Slope - ray.Slope);
  10.       let y = this.Slope*x + this.Intercept;
  11.      
  12.       // Check Y value for THIS Ray
  13.       let xR = new Engine.DirectedRange(this.A.Y,this.B.Y);
  14.       let xPct = xR.Percent(x);
  15.       if(xPct < 0 || xPct > 1){
  16.         return false;
  17.       }
  18.      
  19.       // Check Y value for OTHER Ray
  20.       xR = new Engine.DirectedRange(ray.A.Y,ray.B.Y);
  21.       xPct = xR.Percent(x);
  22.       if(xPct < 0 || xPct > 1){
  23.         return false;
  24.       }
  25.      
  26.       // Check Y value for THIS Ray
  27.       let yR = new Engine.DirectedRange(this.A.Y,this.B.Y);
  28.       let yPct = yR.Percent(y);
  29.       if(yPct < 0 || yPct > 1){
  30.         return false;
  31.       }
  32.      
  33.       // Check Y value for OTHER Ray
  34.       yR = new Engine.DirectedRange(ray.A.Y,ray.B.Y);
  35.       yPct = yR.Percent(y);
  36.       if(yPct < 0 || yPct > 1){
  37.         return false;
  38.       }
  39.      
  40.       return true;
  41.  
  42.    }
  43. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top