Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove inside faces #18

Open
wants to merge 7 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 66 additions & 38 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@
}

var geometry=new THREE.Geometry();
geometry.verticesNeedUpdate=true;

var spline=new THREE.SplineCurve3(points);
var splinePoints=spline.getPoints(points.length-1);

for(i=0; i<splinePoints.length; i++){
if(Math.abs((spline.points[i]).z)<=size){
geometry.vertices.push(spline.points[i]);
Expand Down Expand Up @@ -144,7 +141,7 @@
return;
}

if(boundY1>boundY2){ //Switch the bounds around so that the for loop works
if(this.bound1>this.bound2){ //Switch the bounds around so that the for loop works
var temp=this.bound2;
this.bound2=this.bound1;
this.bound1=temp;
Expand All @@ -165,19 +162,19 @@
console.log(" Both boundY1 and boundY2 are greater than or equal to 0");
if(graph2ComparingPoint1>graph1ComparingPoint1 && graph2ComparingPoint2>graph1ComparingPoint2){
console.log(" Graph2 is higher than graph1");
this.addBSP("this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+0.5)", "this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+0.5)");
this.addBSP("this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+step)", "this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)");
} else {
console.log(" Graph2 is lower than or equal to graph1");
this.addBSP("this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+0.5)", "this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+0.5)");
this.addBSP("this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)", "this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+step)");
}
} else {
console.log(" One of the bounds is less than 0");
if(graph2ComparingPoint1>graph1ComparingPoint1 && graph2ComparingPoint2>graph1ComparingPoint2){
console.log(" Graph2 is higher than graph1");
this.addBSP("this.axisOfRotation+Math.abs(graphArray[1].getY(i))", "this.axisOfRotation+Math.abs(graphArray[1].getY(i+0.5))", "this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+0.5)");
this.addBSP("this.axisOfRotation+Math.abs(graphArray[1].getY(i))", "this.axisOfRotation+Math.abs(graphArray[1].getY(i+step))", "this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)");
} else {
console.log(" Graph2 is lower than or equal to graph1");
this.addBSP("this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+0.5)", "this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+0.5)");
this.addBSP("this.axisOfRotation-this.getY(i)", "this.axisOfRotation-this.getY(i+step)", "this.axisOfRotation-graphArray[1].getY(i)", "this.axisOfRotation-graphArray[1].getY(i+step)");
}
}
} else if(this.axisOfRotation<=boundY1 && this.axisOfRotation<=graphArray[1].getY(this.bound1)){
Expand All @@ -186,19 +183,19 @@
console.log(" Both boundY1 and boundY2 are greater than or equal to 0");
if(graph2ComparingPoint1>graph1ComparingPoint1 && graph2ComparingPoint2>graph1ComparingPoint2){
console.log(" Graph2 is higher than graph1");
this.addBSP("Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+0.5)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i+0.5)");
this.addBSP("Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+step)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i+step)");
} else {
console.log(" Graph2 is lower than or equal to graph1");
this.addBSP("Math.abs(this.axisOfRotation)+graphArray[1].getY(i)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i+0.5)", "Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+0.5)");
this.addBSP("Math.abs(this.axisOfRotation)+graphArray[1].getY(i)", "Math.abs(this.axisOfRotation)+graphArray[1].getY(i+step)", "Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+step)");
}
} else {
console.log(" One of the bounds is less than 0");
if(graph2ComparingPoint1>graph1ComparingPoint1 && graph2ComparingPoint2>graph1ComparingPoint2){
console.log(" Graph2 is higher than graph1");
this.addBSP("Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+0.5))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i+0.5))");
this.addBSP("Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+step))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i+step))");
} else {
console.log(" Graph2 is lower than or equal to graph1");
this.addBSP("Math.abs(this.axisOfRotation-graphArray[1].getY(i))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i+0.5))", "Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+0.5))");
this.addBSP("Math.abs(this.axisOfRotation-graphArray[1].getY(i))", "Math.abs(this.axisOfRotation-graphArray[1].getY(i+step))", "Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+step))");
}
}
} else {
Expand All @@ -211,54 +208,88 @@
console.log(" BoundY1 is equal to boundY2 and bound1 does not equal bound2");
if(this.axisOfRotation>boundY1){
console.log(" Axis of rotation is greater than boundY1");
this.addBSP("Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+0.5))", "Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)");
this.addBSP("Math.abs(this.axisOfRotation-this.getY(i))", "Math.abs(this.axisOfRotation-this.getY(i+step))", "Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)");
} else if(this.axisOfRotation<boundY1){
console.log(" Axis of rotation is less than boundY1");
this.addBSP("Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+0.5)");
this.addBSP("Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)", "Math.abs(this.axisOfRotation)+this.getY(i)", "Math.abs(this.axisOfRotation)+this.getY(i+step)");
} else if(this.axisOfRotation===boundY1){
console.log(" Axis of rotation is equal to boundY1");
this.addSolidWithoutHoles("Math.abs(this.getY(i))", "Math.abs(this.getY(i+this.quality))");
this.addSolidWithoutHoles("Math.abs(this.getY(i))", "Math.abs(this.getY(i+step))");
}
}
} else {
console.log("Axis of rotation is 0");
this.addSolidWithoutHoles("Math.abs(this.getY(i))", "Math.abs(this.getY(i+this.quality))");
this.addSolidWithoutHoles("Math.abs(this.getY(i))", "Math.abs(this.getY(i+step))");
}
scene.add(this.group);
render();
};

Graph.prototype.addBSP=function(smallGeoR1, smallGeoR2, bigGeoR1, bigGeoR2){
for(var i=this.bound1; i<this.bound2; i+=0.5){
Graph.prototype.addBSP=function(innerCylinderSmallRadius, innerCylinderLargeRadius, outerCylinderSmallRadius, outerCylinderLargeRadius){
var step=this.quality;
for(var i=this.bound1; i<this.bound2; i+=step){
if(this.getY(i)<=size){
if(!eval(smallGeoR1) || !eval(smallGeoR2)){ //Hacky bugfix woo
smallGeoR1=smallGeoR1 + "+0.01";
smallGeoR2=smallGeoR2 + "+0.01";
if(!eval(innerCylinderSmallRadius) || !eval(innerCylinderLargeRadius)){ //Hacky bugfix woo
innerCylinderSmallRadius=innerCylinderSmallRadius + "+0.01";
innerCylinderLargeRadius=innerCylinderLargeRadius + "+0.01";
}

if(i+step>this.bound2) //Prevent the solid from extending beyond the second bound if it can't be divided by the quality
{
step=this.bound2-i;
}

var smallCylinder, largeCylinder;
if(i===this.bound1)
{
smallCylinder=new THREE.CylinderGeometry(eval(innerCylinderSmallRadius), eval(innerCylinderLargeRadius), step, 50, 1, false, true);
largeCylinder=new THREE.CylinderGeometry(eval(outerCylinderSmallRadius), eval(outerCylinderLargeRadius), step, 360, 1, false, true);
}
else if(i+step>=this.bound2)
{
smallCylinder=new THREE.CylinderGeometry(eval(innerCylinderSmallRadius), eval(innerCylinderLargeRadius), step, 50, 1, true, false);
largeCylinder=new THREE.CylinderGeometry(eval(outerCylinderSmallRadius), eval(outerCylinderLargeRadius), step, 360, 1, true, false);
}
else
{
smallCylinder=new THREE.CylinderGeometry(eval(innerCylinderSmallRadius), eval(innerCylinderLargeRadius), step, 50, 1, true, true);
largeCylinder=new THREE.CylinderGeometry(eval(outerCylinderSmallRadius), eval(outerCylinderLargeRadius), step, 360, 1, true, true);
}
smallCylinder.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i+step/2), -this.axisOfRotation));
largeCylinder.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i+step/2), -this.axisOfRotation));

var smallCylinderGeom=new THREE.CylinderGeometry(eval(smallGeoR1), eval(smallGeoR2), 0.5, 50);
smallCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i+0.5/2), -this.axisOfRotation));
var largeCylinderGeom=new THREE.CylinderGeometry(eval(bigGeoR1), eval(bigGeoR2), 0.5, 360);
largeCylinderGeom.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i+0.5/2), -this.axisOfRotation));
var smallCylinderBSP=new ThreeBSP(smallCylinderGeom);
var largeCylinderBSP=new ThreeBSP(largeCylinderGeom);
var intersectionBSP=largeCylinderBSP.subtract(smallCylinderBSP);
var material=new THREE.MeshPhongMaterial({color: 0xffff00/*, transparent: true, opacity: 0.5*/});
var hollowCylinder=intersectionBSP.toMesh(material);
var hollowCylinder=new ThreeBSP(largeCylinder).subtract(new ThreeBSP(smallCylinder)).toMesh(new THREE.MeshPhongMaterial({color: 0xffff00, transparent: true, opacity: 0.5}));
hollowCylinder.rotation.set(0, 0, Math.PI/2);
this.group.add(hollowCylinder);
}
}
};

Graph.prototype.addSolidWithoutHoles=function(leftRadius, rightRadius){
for(var i=this.bound1; i<this.bound2; i+=this.quality){
var step=this.quality;
for(var i=this.bound1; i<this.bound2; i+=step){
if(this.getY(i)<=size){
var geometry=new THREE.CylinderGeometry(eval(leftRadius), eval(rightRadius), this.quality, 100);
geometry.verticesNeedUpdate=true;
geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i+this.quality/2), -this.axisOfRotation));
if(i+step>this.bound2) //Prevent the solid from extending beyond the second bound if it can't be divided by the quality
{
step=this.bound2-i;
}

var material=new THREE.MeshPhongMaterial({color: 0xffff00/*, transparent: true, opacity: 0.5*/});
var geometry;
if(i===this.bound1)
{
geometry=new THREE.CylinderGeometry(eval(leftRadius), eval(rightRadius), step, 100, 1, false, true);
}
else if(i+step>=this.bound2)
{
geometry=new THREE.CylinderGeometry(eval(leftRadius), eval(rightRadius), step, 100, 1, true, false);
}
else
{
geometry=new THREE.CylinderGeometry(eval(leftRadius), eval(rightRadius), step, 100, 1, true, true);
}
geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, -(i+step/2), -this.axisOfRotation));

var material=new THREE.MeshPhongMaterial({color: 0xffff00, transparent: true, opacity: 0.5});
var plane=new THREE.Mesh(geometry, material);
plane.material.color.setHex(0xffff00);

Expand Down Expand Up @@ -353,10 +384,7 @@

function addAxis(){
var geometry=new THREE.Geometry();
geometry.verticesNeedUpdate=true;

var axes=new THREE.Geometry();
axes.verticesNeedUpdate=true;

for(var i=-size; i<=size; i+=1){
if(i){
Expand Down
4 changes: 2 additions & 2 deletions js/three.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.