Mon 25 Nov 2013 10:50:31 AM UTC, comment #4:
I would rather use the methods already applied in geometry_menu,
something along the following lines:
We should probably make a Coords.orientedBbox(ctr,rot) and a principalBbox() which calls orientedBbox with the inertia data.
|
Mon 25 Nov 2013 08:09:50 AM UTC, original submission:
I would like to include an oriented bounding box (based on the inertia) in coords, but I am not sure if it can be consistent with the current pyformex style. The advantage is that the bbox is smaller and better oriented with the points. this is the code I propose but can probably be improved.
def obb(coords):
from geomtools import intersectionPointsLWP
from plugins import inertia
C,I = inertia.inertia(coords)
inprin,inaxis = inertia.principal(I)
inaxis=inaxis.T
dmin=[]
dmax=[]
for i in range(3):
dtmp=intersectionPointsLWP(coords,resize(inaxis[i],coords.shape),C,inaxis[i],mode='pair')
dmin.append((length(dtmp-coords)*sign(inner((coords-dtmp),inaxis[i]))).min())
dmax.append((length(dtmp-coords)*sign(inner((coords-dtmp),inaxis[i]))).max())
dmax=asarray([dmax])
dmin=asarray([dmin])
b=(dmax-dmin).T*inaxis
crn0=C+(inaxis*dmin.T).sum(axis=0)
crn1=crn0+b[2]
crn2=crn0+b[2]+b[1]
crn3=crn0+b[1]
crn4=crn0+b[0]
crn5=crn0+b[0]+b[2]
crn6=crn0+b[0]+b[1]+b[2]
crn7=crn0+b[0]+b[1]
cbox=Coords(row_stack([crn0,crn1,crn2,crn3,crn4,crn5,crn6,crn7]))
ebox=arange(8)[None,:]
box=Mesh(cbox,ebox)
return box
|