Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Line(placePoint, endPoint) {
- this.placePoint = placePoint;
- this.endPoint = endPoint;
- this.testWith = function(lineB) {
- var lambdaA = this.getLambda(lineB);
- if(lambdaA >= 0 && lambdaA <= 1) {
- var lambdaB = lineB.getLambda(this);
- if(lambdaB >= 0 && lambdaB <= 1) {
- // return the point of intersection:
- return lineB.getDirectionPoint().multiply(lambdaA).add(placePoint);
- }
- }
- return null;
- }
- this.getLambda = function(lineB) {
- var rn = this.getDirectionPoint().dotProduct(lineB.getNormalized());
- var sn = placePoint.dotProduct(lineB.getNormalized());
- return (lineB.getConstante() - sn) / rn;
- }
- this.getDirectionPoint = function() {
- // Vector AB = B-A
- return endPoint.substract(placePoint);
- }
- this.getNormalized = function(lineB) {
- return this.getDirectionPoint().perp().normalize();
- }
- this.getConstante = function() {
- return placePoint.dotProduct(this.getNormalized());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment