Add line separation algorithm

parent 269cbb29
......@@ -812,6 +812,10 @@ define(function(require, exports, module){
return BSPTree.sign(normal.dot(point.clone().sub(pointOnPlane)));
}
BSPTree.isZero = function(x){
return Math.abs(x) < BSPTree.SIGN_EPSILON;
}
BSPTree.sign = function(x){
if(Math.abs(x) < BSPTree.SIGN_EPSILON){
return 0;
......@@ -884,7 +888,21 @@ define(function(require, exports, module){
}
BSPTree.LineNode.prototype.separate = function(normal, point){
var upper = point.clone().sub(this.element.v1.positionWorld);
upper = upper.dot(normal);
var l0 = this.element.v2.positionWorld;
var l = l0.clone().sub(this.element.v1.positionWorld);
var lower = l.dot(normal);
if(lower === 0) return this;
var d = upper / lower;
var intersectionPoint = l.multiplyScalar(d).add(l0);
return intersectionPoint;
}
BSPTree.TriangleNode = function(element){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment