Issue with bounding box

Hello All,

I am trying to calculate the end point with the help of bounding box.

Please see the attached png file.

When my plan is straight than i am not facing any issue. Means after getting the center point by getCenter(). Adding the plan length i am getting the mid point of one edge. But when my plan is rotated so still getCenter method is giving me the accurate center but after adding the length i am not able to situate the point at the edge.

Here i think that the point need an rotation like an mesh than it is able to move properly. But i dont know how to do that.

My second question is

I am reading the ways to align the bounding box with the object, i found OBB class and some article but they are not very clear to me.

Please any help from you guzs really value to me.

Thanks

You can’t use Box3 for this since this class computes the axis-aligned bounding box. That means it is never rotated but as the name implies aligned to the XYZ axes.

OBB is an oriented bounding box. Once setup, it can arbitrarily be rotated in 3D space. The center property represents the center of the OBB whereas the halfSize describes the positive halfwidth extents of the OBB along each axis. You can use both properties to compute points along the OBBs sides. Since the rotation property is of type Matrix3, you can use Vector3.applyMatrix3() to transform a given point with the rotation matrix.

I suggest you study the official example to understand how to apply the transformation of a 3D object (in your case the plane) to its OBB.

This is not clear to me.

Please can you explain this statement to me

A box has a spatial extension along the X, Y and Z axis. The halfwidth vector says how far you have to go from the center along each axis to reach the (positive) sides of the box.

1 Like

I am using this formula,

obb = new OBB()
obb.fromBox3(geometry.boundingBox)

vec = new THREE.Vector3(obb.center.x + obb.halfSize.x, 0,obb.center.z + obb.halfSize.z)

More precise
if halfwidth =
vec = new THREE.Vector3(1+.5,0,1+.5)
This results in

vec (1.5,0.1.5)

And you specifically mentioned the positive sides , what if the plane is in the negative quadrate.

in my case how i use OBB

i put in a array all objet i need to manage for collision

listForCollision.push({o:scene.getObjectByName(‘nameofmyobjet1’),obb:new OBB()});
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjet2’),obb:new OBB()});
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjet3’),obb:new OBB()});

listForCollision.push({o:scene.getObjectByName(‘nameofmyobjetn’),obb:new OBB() , dx:-0.25 ,dy:-0.25 ,dz:0 });
listForCollision.push({o:scene.getObjectByName(‘nameofmyobjetm’),obb:new OBB(), dx:0 ,dy:0 ,dz:1} );

after i create obb for all objet in the array
for(var i=0,longueur=listForCollision.length;i<longueur;i++){
createOBB(listForCollision[i]);

		               }

and function is ( delta is to add or substract length to OBB )

function createOBB(monObjet){
var delta = new THREE.Vector3( 0.25 , 0.25, 0.25 ) ;

			  if ( monObjet.dx !== undefined ) { delta.x  = monObjet.dx ;}
		     if ( monObjet.dy !== undefined ) { delta.y = monObjet.dy ;}
      	  if ( monObjet.dz !== undefined ) { delta.z = monObjet.dz ;}
      	  
          // get opposite of rotation objet axe Z 	      	  
		
          var monquater=new THREE.Quaternion();
           monquater.set(0,0,-monObjet.o.quaternion.z,monObjet.o.quaternion.w);
           
          //clone objet to create OBB and rotate clone around axe Z 
                         
          var monObjetDouble=monObjet.o.clone(true);
          monObjetDouble.applyQuaternion(monquater);
          
          //create box and set it with clone               
          
          var monAABB = new THREE.Box3();
          monAABB.setFromObject( monObjetDouble );
          
          // add delta
            
          monAABB.min.subVectors(monAABB.min,delta);
          monAABB.max.addVectors(monAABB.max,delta);
    
          // create helperbox to see box  
          
          var helperbox=new THREE.Box3Helper(monAABB,0xffffff);
          scene.add(helperbox);
        
         // get center and half dim of box3 
             
          var moncentre = new THREE.Vector3() ;
         monAABB.getCenter(moncentre);
         
         var mondim = new THREE.Vector3();
         monAABB.getSize(mondim);
         mondim.multiplyScalar(0.5);
         
         
         var monAngle = 0;
         var angle=Math.acos(monObjet.o.quaternion.w);
         var signe=Math.asin(monObjet.o.quaternion.z);
         
         if ( signe > 0 ) { monAngle = 2*angle ; }
         else { monAngle = 2* ( 2*Math.PI - angle) }
     
    
          var xxxx=Math.cos(monAngle),yyyy=Math.sin(monAngle);
           
         // rotate helperbox 
                        
          helperbox.setRotationFromAxisAngle(new THREE.Vector3(0,0,1),monAngle);
          
          //set OBB 
          
        monObjet.obb.set(new THREE.Vector3(moncentre.x,moncentre.y,moncentre.z), new THREE.Vector3(mondim.x,mondim.y,mondim.z), new  THREE.Matrix3().set(xxxx,-yyyy,0,yyyy,xxxx,0,0,0,1) ) ;
         monObjet.helperBox=helperbox; 
		
		
		
		}

and result with helperbox visible .

In my case i think i dont need any OBB though, only i need an formula to calculate the lower left corner of my geometry that is about to render.

If you see my png so my geometries are 2d- plan. Than are in xz axis and can me at 45, 90, 120 any degree rotation in xz plan. I see i have an center point and with respect to center if there is any way or formula to get the corner point. This is really helpfull. I tried OBB but i am not very clear with the statements. But still i know they have deep meaning and helpfull

Please check my png

once you have your initial coord of vector( your vec = new THREE.Vector3(1+.5,0,1+.5) ) you have just need to rotate and you will get new coordinate

all method of vector3 are available here

three.js docs

you have

a) .applyAxisAngle ( axis : Vector3, angle : Float ) : this

axis - A normalized Vector3.
angle - An angle in radians.

b) .applyQuaternion ( quaternion : Quaternion ) : this

Applies a Quaternion transform to this vector.