In [1]:
import sys,os,imp
import math
import numpy as np
import matplotlib as mpl
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cmx
#this works apparently only for savefig stuff
mpl.rcParams['figure.figsize']=(6.0,4.0) #(6.0,4.0)
mpl.rcParams['font.size']=10 #10
mpl.rcParams['savefig.dpi']=400 #72
mpl.rcParams['figure.subplot.bottom']=.1 #.125
plt.rc('font', family='serif')
plt.rc('text', usetex=True)
#inline Shit
%matplotlib inline
%config InlineBackend.figure_format='svg'
%config InlineBackend.rc = {'figure.facecolor': 'white', 'figure.subplot.bottom': 0.125, 'figure.edgecolor': 'white', 'savefig.dpi': 400, 'figure.figsize': (12.0, 8.0), 'font.size': 10}
#GUi shit
%matplotlib tk
mpl.get_configdir()
%load_ext autoreload
%autoreload 2
# Import General Packages from me
from Tools.Parsers import *
from Tools.BoundingBox import *
from Tools.Transformations import *
In [2]:
from scipy.spatial import ConvexHull
from mpl_toolkits.mplot3d import Axes3D
def rotMatrix(axis,theta):
axis = axis/math.sqrt(np.dot(axis,axis))
a = math.cos(theta/2)
b,c,d = axis*math.sin(theta/2)
return np.array([[a*a+b*b-c*c-d*d, 2*(b*c-a*d), 2*(b*d+a*c)],
[2*(b*c+a*d), a*a+c*c-b*b-d*d, 2*(c*d-a*b)],
[2*(b*d-a*c), 2*(c*d+a*b), a*a+d*d-b*b-c*c]]);
def plotCube(minP = np.array([-1.0,-1.0,-1.0]), maxP=np.array([1.0,1.0,1.0]),
trans= np.array([0.0,0.0,0.0]),rotationMatrix=np.diag([1,1,1])):
from itertools import product, combinations
r = [-1, 1]
centerPos = (maxP + minP)/2.0;
print(centerPos)
extent = (maxP - minP)/2.0;
points = np.array([(-1, -1, -1),
(-1, -1, 1),
(-1, 1, -1),
(-1, 1, 1),
(1, -1, -1),
(1, -1, 1),
(1, 1, -1),
(1, 1, 1)]);
for s, e in combinations(points, 2):
if np.sum(np.abs(s-e)) == r[1]-r[0]: # no diagonal lines
p1 = np.array(s,dtype=float); p2 = np.array(e,dtype=float);
#scale points
p1*=extent; p2*=extent;
#rotate and translate points
p1 = rotationMatrix.dot(p1 + centerPos) + trans;
p2 = rotationMatrix.dot(p2+centerPos) + trans;
ax.plot3D(*zip(p1,p2), color="b")
def plotAxis(centerPos,A_IK,plotAxisScale=1):
for i,c in zip([0,1,2],['r','g','b']):
I_eK_i = A_IK[:,i];
lines = list(zip(centerPos,plotAxisScale*I_eK_i+centerPos))
v = Arrow3D(*lines, mutation_scale=50, lw=1, arrowstyle="-|>", color=c);
ax.plot3D(*lines, color=c)
ax.add_artist(v);
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d
class Arrow3D(FancyArrowPatch):
def __init__(self, xs, ys, zs, *args, **kwargs):
FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
self._verts3d = xs, ys, zs
def draw(self, renderer):
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
FancyArrowPatch.draw(self, renderer)
def makeSkewSym3(a):
m = np.zeros((3,3));
m[0,0]=a[0];
m[0,1]=a[1]; m[1,0]=a[1];
m[0,2]=a[2]; m[2,0]=a[2];
m[1,1]=a[3];
m[1,2]=a[4]; m[2,1]=a[4];
m[2,2]=a[5];
return m;
def calculateBoundingBoxBinetTensor(pointsIn, withConvexHull=False):
I_theta_G = np.zeros((6,1));
I_r_G = np.zeros((3));
points = pointsIn.copy();
if(withConvexHull):
from scipy.spatial import ConvexHull
hull = ConvexHull(points.T)
points = points[:,hull.vertices];
print("Computed Convex Hull")
nPoints = points.shape[1];
for p in points.T:
# print(type(p),p.ndim)
# print(I_r_G.shape,p.shape)
I_r_G += p;
I_theta_G[0] += p[0]*p[0];
I_theta_G[1] += p[0]*p[1];
I_theta_G[2] += p[0]*p[2];
I_theta_G[3] += p[1]*p[1];
I_theta_G[4] += p[1]*p[2];
I_theta_G[5] += p[2]*p[2];
I_r_G /= nPoints;
# move binet tensor to center of mass G [mass for every point m=1]
I_theta_G[0] -= I_r_G[0]*I_r_G[0] * nPoints;
I_theta_G[1] -= I_r_G[0]*I_r_G[1] * nPoints;
I_theta_G[2] -= I_r_G[0]*I_r_G[2]* nPoints;
I_theta_G[3] -= I_r_G[1]*I_r_G[1]* nPoints;
I_theta_G[4] -= I_r_G[1]*I_r_G[2]* nPoints;
I_theta_G[5] -= I_r_G[2]*I_r_G[2]* nPoints;
print("Computed Binet Inertia Tensor")
A = makeSkewSym3(I_theta_G);
print("I_Theta_G: " , A);
eigs = np.linalg.eigh(A);
A_IK = eigs[1];
print("Computed Binet Inertia Tensor, Eigenvector Decomposition")
A_IK[:,0] /= np.linalg.norm(A_IK[:,0]);
A_IK[:,1] /= np.linalg.norm(A_IK[:,1]);
A_IK[:,2] /= np.linalg.norm(A_IK[:,2]);
#find projected maximas
minP = np.zeros((3));
maxP = np.zeros((3));
for p in points.T:
x = A_IK.T.dot(p - I_r_G);
maxP = np.maximum(maxP,x);
minP = np.minimum(minP,x);
print("Computed Bounding Box")
print("A_IK: " ,A_IK)
print("orthnormality: " ,A_IK.dot(A_IK.T))
print("min: " ,minP)
print("max: " ,maxP)
return (I_r_G,A_IK,minP,maxP,points); # returns A_IK;
In [3]:
def axisEqual3D(ax):
extents = np.array([getattr(ax, 'get_{}lim'.format(dim))() for dim in 'xyz'])
sz = extents[:,1] - extents[:,0]
centers = np.mean(extents, axis=1)
maxsize = max(abs(sz))
r = maxsize/2
for ctr, dim in zip(centers, 'xyz'):
getattr(ax, 'set_{}lim'.format(dim))(ctr - r, ctr + r)
In [8]:
fig = plt.figure(1,(10,10))
ax = Axes3D(fig)
np.random.seed(101)
# points = np.random.rand(3,6000)
points = np.array([(-1, -1, -1),
(-1, -1, 1),
(-1, 1, -1),
(-1, 1, 1),
(1, -1, -1),
(1, -1, 1),
(1, 1, -1),
(1, 1, 1),
(1,1,1),
(0.01,0.5,0.1)],dtype=float).T;
ax.scatter(points[0],points[1],points[2])
# points = np.append(points,points*0.5,0)
# points = np.append(points,points*0.3,0)
# points = np.append(points,points*0.1,0)
# print(points)
# points = points.T
# version 1.0.x syntax:
#ax = fig.add_subplot(111, projection='3d')
# version 0.99.x syntax: (accepted by 1.0.x as well)
# R_KI= rotMatrix(np.array([1,0,0]),20/180.0*math.pi);
# R_KI = R_KI.dot(rotMatrix(np.array([0,0,1]),20/180.0*math.pi));
# trans = np.array([0.2,0,0])
# minP = np.array([-2,-1,-1]);
# maxP = np.array([2,1,1]);
# center = (maxP + minP)/2 + trans;
# plotCube(minP,maxP,trans,R_KI)
# plotAxis(center,R_KI,1)
#ax.scatter(points[0],points[1],points[2])
center, A_IK, minP, maxP, pointsOut = calculateBoundingBoxBinetTensor(points,False)
ax.scatter(pointsOut[0],pointsOut[1],pointsOut[2],color='r')
plotCube(minP,maxP,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
axisEqual3D(ax)
In [10]:
fig = plt.figure(1,(10,10))
ax = Axes3D(fig)
v, t, n, f = ObjLoader.loadObj("./Tools/BoundingBox/TestFiles/bunny.obj");
v = v.T;
nP = 100000;
v = v[:,0:-1]
# v = np.random.rand(3,100)
# print(v.shape)
center, A_IK, minP, maxP, pointsOut = calculateBoundingBoxBinetTensor(v,True)
ax.scatter(pointsOut[0],pointsOut[1],pointsOut[2],color='r')
plotCube(minP,maxP,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
# center, A_IK, minP, maxP, pointsOut = calculateBoundingBoxBinetTensor(v,False)
# ax.scatter(pointsOut[0],pointsOut[1],pointsOut[2],color='r')
# plotCube(minP,maxP,center,A_IK) # A_IK = R_KI (rotation from I to K)
# plotAxis(center,A_IK,1)
axisEqual3D(ax)
In [11]:
points = np.random.rand(30, 3) # 30 random points in 2-D
hull = ConvexHull(points)
hull.vertices
Out[11]:
In [19]:
def parseNDArray(f, dt, deli=" ", comm='#'):
#build structred types (dtype for numpy)
return np.loadtxt(f,dtype=dt, delimiter=deli, comments=comm);
points = parseNDArray("../PointsSimulation.txt" , dt=float )
fig = plt.figure(1,(10,10))
ax = Axes3D(fig)
pointsT = points.T #points = [[x,y,z],[x,y,z]]
#center, A_IK, minP, maxP, pointsOut = calculateBoundingBoxBinetTensor(points,True)
ax.scatter(pointsT[0],pointsT[1],pointsT[2],color='r')
hull = ConvexHull(points)
#print("Points:", points)
# Make Edge Set
edgeSet = set();
for simplex in hull.simplices:
edgeSet.add(CalculateMVBB.Edge( simplex[0], simplex[1] ));
edgeSet.add(CalculateMVBB.Edge( simplex[1], simplex[2] ));
edgeSet.add(CalculateMVBB.Edge( simplex[2], simplex[0] ));
#print(simplex)
print("Edges: ", len(edgeSet), "instead of " , len(hull.simplices)*3)
# for e in edgeSet:
# print(e[0],e[1]);
for simplex in hull.simplices:
ax.plot(points[simplex,0], points[simplex,1], points[simplex,2], 'k-')
corner, v1, v2, v3, u,v,w = CalculateMVBB.findOBBEdge(list(edgeSet),points)
print(v1,v2,v3)
In [20]:
np.array([u,v,w])
Out[20]:
In [51]:
3<float("inf")
Out[51]:
In [15]:
plt.close('all')
points = np.loadtxt("../ConvexHullTest1.txt");
hullP = np.loadtxt("../ConvexHullTest1Out.txt");
fig = plt.figure(1,(10,10))
hullP = np.vstack((hullP,hullP[0]))
plt.scatter(points.T[0],points.T[1])
plt.plot(hullP.T[0],hullP.T[1],'b-o',ms=20, markerfacecolor='None')
Out[15]:
In [6]:
points = np.loadtxt("../ConvexHullTest2.txt");
hullP = np.loadtxt("../ConvexHullTest2Out.txt");
fig = plt.figure(2,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'b-o',ms=20, markerfacecolor='None')
In [16]:
points = np.loadtxt("../ConvexHullTest3.txt");
hullP = np.loadtxt("../ConvexHullTest3Out.txt");
fig = plt.figure(3,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'b-o',ms=20, markerfacecolor='None')
Out[16]:
In [17]:
points = np.loadtxt("../ConvexHullTest4.txt");
hullP = np.loadtxt("../ConvexHullTest4Out.txt");
fig = plt.figure(4,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'b-o',ms=20, markerfacecolor='None')
Out[17]:
In [18]:
points = np.loadtxt("../ConvexHullTest5.txt");
hullP = np.loadtxt("../ConvexHullTest5Out.txt");
fig = plt.figure(5,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'b-o', ms=20, markerfacecolor='None')
In [19]:
points = np.atleast_2d(np.loadtxt("../ConvexHullTest6.txt"));
hullP = np.atleast_2d(np.loadtxt("../ConvexHullTest6Out.txt"));
fig = plt.figure(6,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'b-o', ms=20, markerfacecolor='None')
Out[19]:
In [20]:
points = np.atleast_2d(np.loadtxt("../ConvexHullTest7.txt"));
hullP = np.atleast_2d(np.loadtxt("../ConvexHullTest7Out.txt"));
fig = plt.figure(7,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'b-o', ms=20, markerfacecolor='None')
Out[20]:
In [21]:
plt.close("all")
points = np.atleast_2d(np.loadtxt("../ConvexHullTest8.txt"));
hullP = np.atleast_2d(np.loadtxt("../ConvexHullTest8Out.txt"));
fig = plt.figure(8,(10,10))
plt.scatter(points.T[0],points.T[1])
nrRange = [(i,p[0],p[1]) for i,p in enumerate(points) ]
for x in nrRange:
plt.annotate('%s' % x[0], xy=x[1:3], textcoords='offset points') # <--
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'b-o', ms=20, markerfacecolor='None')
Out[21]:
In [22]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest1.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest1Out.txt"));
fig = plt.figure(1,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
plt.axis('equal')
Out[22]:
In [23]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest2.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest2Out.txt"));
fig = plt.figure(2,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
plt.axis('equal')
Out[23]:
In [24]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest3.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest3Out.txt"));
fig = plt.figure(3,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
plt.axis('equal')
Out[24]:
In [25]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest4.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest4Out.txt"));
fig = plt.figure(4,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
plt.axis('equal')
Out[25]:
In [26]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest5.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest5Out.txt"));
fig = plt.figure(5,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
plt.axis('equal')
Out[26]:
In [27]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest6.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest6Out.txt"));
fig = plt.figure(6,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
plt.axis('equal')
Out[27]:
In [28]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest7.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest7Out.txt"));
fig = plt.figure(7,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
#plt.axis('equal')
Out[28]:
In [29]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest8.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest8Out.txt"));
fig = plt.figure(8,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
#plt.axis('equal')
Out[29]:
In [29]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest10.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest10Out.txt"));
fig = plt.figure(10,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
#plt.axis('equal')
Out[29]:
In [ ]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest11.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest11Out.txt"));
fig = plt.figure(11,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
#plt.axis('equal')
In [4]:
points = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest12.txt"));
hullP = np.atleast_2d(np.loadtxt("../MinAreaRectangleTest12Out.txt"));
fig = plt.figure(12,(10,10))
plt.scatter(points.T[0],points.T[1])
hullP = np.vstack((hullP,hullP[0]))
plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
plt.axis('equal')
Out[4]:
In [23]:
points = np.atleast_2d(np.loadtxt("../DiameterTest1.txt"));
OOBB = np.atleast_2d(np.loadtxt("../DiameterTest1Out.txt"));
sampled = np.atleast_2d(np.loadtxt("../DiameterTest1Out2.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(1,(10,10))
ax = Axes3D(fig)
ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
ax.scatter(sampled.T[0],sampled.T[1],sampled.T[2],c='r', marker='o', s=200)
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [10]:
points = np.atleast_2d(np.loadtxt("../DiameterTest2.txt"));
OOBB = np.atleast_2d(np.loadtxt("../DiameterTest2Out.txt"));
sampled = np.atleast_2d(np.loadtxt("../DiameterTest2Out2.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(2,(10,10))
ax = Axes3D(fig)
ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
ax.scatter(sampled.T[0],sampled.T[1],sampled.T[2],c='r', marker='o', s=200)
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [9]:
#points = np.atleast_2d(np.loadtxt("../DiameterTest3.txt"));
OOBB = np.atleast_2d(np.loadtxt("../DiameterTest3Out.txt"));
sampled = np.atleast_2d(np.loadtxt("../DiameterTest3Out2.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(3,(10,10))
ax = Axes3D(fig)
#ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
ax.scatter(sampled.T[0],sampled.T[1],sampled.T[2],c='r', marker='o', s=200)
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [8]:
plt.close("all")
points = np.atleast_2d(np.loadtxt("../DiameterTest4.txt"));
OOBB = np.atleast_2d(np.loadtxt("../DiameterTest4Out.txt"));
sampled = np.atleast_2d(np.loadtxt("../DiameterTest4Out2.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(4,(10,10))
ax = Axes3D(fig)
ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
ax.scatter(sampled.T[0],sampled.T[1],sampled.T[2],c='r', marker='o', s=200)
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
# Somethings are wrong with min area rectangle (load it)
# points = np.atleast_2d(np.loadtxt("../computeMVBBIn.txt"));
# hullP = np.atleast_2d(np.loadtxt("../computeMVBBRect.txt"));
# fig = plt.figure(8,(10,10))
# plt.scatter(points.T[0],points.T[1])
# hullP = np.vstack((hullP,hullP[0]))
# plt.plot(hullP.T[0],hullP.T[1],'r-', ms=20, markerfacecolor='None')
#plt.axis('equal')
In [13]:
plt.close("all")
OOBB = np.atleast_2d(np.loadtxt("../DiameterTest5Out.txt"));
sampled = np.atleast_2d(np.loadtxt("../DiameterTest5Out2.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(5,(10,10))
ax = Axes3D(fig)
# ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
ax.scatter(sampled.T[0],sampled.T[1],sampled.T[2],c='r', marker='o', s=200)
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [30]:
plt.close("all")
OOBB = np.atleast_2d(np.loadtxt("../DiameterTest6Out.txt"));
sampled = np.atleast_2d(np.loadtxt("../DiameterTest6Out2.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(5,(10,10))
ax = Axes3D(fig)
# ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
ax.scatter(sampled.T[0],sampled.T[1],sampled.T[2],c='r', marker='o', s=200)
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [ ]:
Ry = Transformations.quaternion_about_axis(m.pi/2,[0,1,0]);
Rz = Transformations.quaternion_about_axis(m.pi/2,[1,0,0]);
R = Transformations.quaternion_multiply(Rz,Ry);
print(R)
print(Transformations.quaternion_matrix(R)[0:3,0:3].dot(np.array([1,0,0]) ))
print(Transformations.quaternion_matrix(R)[0:3,0:3].dot(np.array([0,1,0]) ))
In [21]:
points = np.atleast_2d(np.loadtxt("../MVBBTest1.txt"));
OOBB = np.atleast_2d(np.loadtxt("../MVBBTest1Out.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(1,(10,10))
ax = Axes3D(fig)
ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [17]:
points = np.atleast_2d(np.loadtxt("../MVBBTest2.txt"));
OOBB = np.atleast_2d(np.loadtxt("../MVBBTest2Out.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(2,(10,10))
ax = Axes3D(fig)
ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [18]:
points = np.atleast_2d(np.loadtxt("../MVBBTest3.txt"));
OOBB = np.atleast_2d(np.loadtxt("../MVBBTest3Out.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(3,(10,10))
ax = Axes3D(fig)
ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [14]:
#points = np.atleast_2d(np.loadtxt("../MVBBTest4.txt"));
OOBB = np.atleast_2d(np.loadtxt("../MVBBTest4Out.txt"));
K_min = OOBB[0,0:3]
K_max = OOBB[1,0:3]
A_IK = OOBB[2:,0:3]
center = np.zeros((3,));
print(A_IK,K_min,K_max,center)
fig = plt.figure(4,(10,10))
ax = Axes3D(fig)
#ax.scatter(points.T[0],points.T[1],points.T[2],c='b')
plotCube(K_min,K_max,center,A_IK) # A_IK = R_KI (rotation from I to K)
plotAxis(center,A_IK,1)
plotAxis(center,np.identity(3),0.5)
axisEqual3D(ax)
In [ ]: