collisionTest

by jason870509

HTML

<div id="normal">normalVector
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/84/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

CSS

#normal {
  position: absolute;
  top: 2%;
  width: 100%;
  padding: 10px;
  color: #000000;
}

JavaScript

var renderer, scene, camera;
var controls;
var circle, circle2;
var mouse = new THREE.Vector2();
var pickables = [];
var rec, mat1, mat2, raycaster, R
var vx=0.2, vy = 0.2, t= 1;
class Box2{
	constructor(){
  	this.max = new THREE.Vector3()
    this.min = new THREE.Vector3()
  }
}

init();
animate();

//r = box2 c = vector3
function check_Intersection(r, c, rad){
	
	var rad2 = rad * rad
  r.max.x -= c.x
  r.max.y -= c.y
  r.min.x -= c.x
  r.min.y -= c.y
  //console.log(r)
  if(r.max.x < 0){
    if(r.max.y < 0){ //left down  1
    	if(((r.max.x * r.max.x + r.max.y * r.max.y) < rad2))
      	return 1
      return 0
      //return ((r.max.x * r.max.x + r.max.y * r.max.y) < rad2)
    }
    else if(r.min.y > 0){ //left up  2
    	if(((r.max.x * r.max.x + r.min.y * r.min.y) < rad2))
      	return 2
      return 0
    	//return ((r.max.x * r.max.x + r.min.y * r.min.y) < rad2)
    }
    else{  //left  3
    	if((Math.abs(r.max.x) < rad))
      	return 3
      return 0
    	//return (Math.abs(r.max.x) < rad)
    }
  }
  else if(r.min.x > 0){
  	if(r.max.y < 0){ //right down  4
    	if(((r.min.x * r.min.x + r.max.y * r.max.y) < rad2))
      	return 4
      return 0
    	//return ((r.min.x * r.min.x + r.max.y * r.max.y) < rad2)
  	}
    else if(r.min.y > 0){ //right up  5
    	if(((r.min.x * r.min.x + r.min.y * r.min.y) < rad2))
      	return 5
      return 0
  		//return ((r.min.x * r.min.x + r.min.y * r.min.y) < rad2)
    }
    else{  //right  6
    	if((r.min.x < rad))
      	return 6
      return 0
    	//return (r.min.x < rad)
    }
  }
  else{
  	if(r.max.y < 0){ //center down  7
    	if((Math.abs(r.max.y) < rad))
      	return 7
      return 0
      //return (Math.abs(r.max.y) < rad)
    }
  	else if(r.min.y > 0){ //center up  8
    	if((r.min.y < rad))
      	return 8
      return 0
      //return (r.min.y < rad)
    }
  	else  //center
    	return 9
  		//return true
  }
  
}

function coordinateOrigin(recMesh, r, c, rad){
	r.max.x = 10 / 2
  r.max.y = 20 / 2
 ...