Notifications
Clear all

[Closed] Selection Position Matrix

Now we are talking

The reason you see this is because selection.center does not return the average of the pivot points positions but the center of the common world-oriented bounding box.

Consider the following revised script:


 	   (
 		   A = box()  -- create 3 boxes
 		   B = box()
 		   C = box()
 		   
 		   -- set the 3 boxes positioned apart, and scale them differently so they are not uniform
 		   
 		   A.pos = [-204.62,-233.351,425.624] ; A.scale = [3.90731,3.90731,3.90731] ; A.name ="Box_in_Selection_01"
 		   B.pos = [-293.596,212.092,210.862] ; B.scale = [4.64474,4.64474,4.64474] ; B.name ="Box_in_Selection_02"
 		   C.pos = [215.864,-193.491,159.17]  ; C.scale = [2.72215,2.72215,2.72215] ; C.name = "Box_in_Selection_03"
 		   
 	
 		   select $Box_in_Selection*							 -- select the newly created boxes
 		   
 		   Box_Selection_Matrix = selection.center 			 -- stores where the supposed center of the selection is
 		   D = box() 	 -- created to compare center location
 		   D.pos = Box_Selection_Matrix ; D.name = "Offset_Box"   -- set the new box's position to be equal to the selection center position
 		   
 	--Create a Recrangle which in Top View shows the bounding box whose center selection.center really marks:
 	r = rectangle width:(selection.max.x-selection.min.x) length:(selection.max.y-selection.min.y) pos:selection.center
 	f = box pos:((A.pos + B.pos + C.pos) /3) name:"Average Pivot" --REAL Center
 	g= box pos:((A.center + B.center + C.center)/3) name:"Average Center" --REAL Center of Centers		   
 		   -- to show where the selection center matrix is located
 		   select $Box_in_Selection* 
 		   toolMode.selectionCenter() -- so that the selection mode is set to selection.center
 	   )

In this case, r is a rectangle which, when viewed from the Top Viewport, denotes the XY projection of the common world-oriented bounding box of the boxes. I placed it at the selection.center and it completely encloses all 3 boxes.

In contrast, the box “Average Pivot” uses the average of the 3 boxes’ positions, thus marking the center based on their pivot points.

The box “Average Centers” takes the average of the 3 bounding boxes’ centers and is probably the center you really wanted to start with. Since boxes have their pivot point at the base, this point is offset up relative from “Average Pivot” and is the closest thing to a real center you can get.

Hope this helps.

ah, that clears things up. Thanks

Page 2 / 2