Created
November 29, 2019 22:39
-
-
Save estama/c0ccb1c237e06d8f5ca90e31e1ef824a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function overlapsOBB_OBB(c1, x1, y1, z1, c2, x2, y2, z2) | |
| local cc = c1 - c2 | |
| local d11, d12, d13 = abs(x1:dot(x2)), abs(x1:dot(y2)), abs(x1:dot(z2)) | |
| local d21, d22, d23 = abs(y1:dot(x2)), abs(y1:dot(y2)), abs(y1:dot(z2)) | |
| local d31, d32, d33 = abs(z1:dot(x2)), abs(z1:dot(y2)), abs(z1:dot(z2)) | |
| return abs(cc:dot(x1))-d11-d12-d13<=x1:squaredLength() and abs(cc:dot(y1))-d21-d22-d23<=y1:squaredLength() and abs(cc:dot(z1))-d31-d32-d33<=z1:squaredLength() | |
| and abs(cc:dot(x2))-d11-d21-d31<=x2:squaredLength() and abs(cc:dot(y2))-d12-d22-d32<=y2:squaredLength() and abs(cc:dot(z2))-d13-d23-d33<=z2:squaredLength() | |
| end | |
| function containsOBB_OBB(c1, x1, y1, z1, c2, x2, y2, z2) | |
| local cc = c1 - c2 | |
| return abs(cc:dot(x1))+abs(x1:dot(x2))+abs(x1:dot(y2))+abs(x1:dot(z2))<=x1:squaredLength() and abs(cc:dot(y1))+abs(y1:dot(x2))+abs(y1:dot(y2))+abs(y1:dot(z2))<=y1:squaredLength() and abs(cc:dot(z1))+abs(z1:dot(x2))+abs(z1:dot(y2))+abs(z1:dot(z2))<=z1:squaredLength() | |
| end | |
| function overlapsOBB_Sphere(c1, x1, y1, z1, c2, r2) | |
| local cc = c1 - c2 | |
| local x1len, y1len, z1len = x1:length(), y1:length(), z1:length() | |
| local ccx, ccy, ccz = abs(cc:dot(x1)), abs(cc:dot(y1)), abs(cc:dot(z1)) | |
| return ccx<=x1len*(x1len+r2) and ccy<=y1len*(y1len+r2) and ccz<=z1len*(z1len+r2) | |
| and (ccx<=x1len*x1len or ccy<=y1len*y1len or ccz<=z1len*z1len or | |
| square(ccx/(x1len+1e-30)-x1len) + square(ccy/(y1len+1e-30)-y1len) + square(ccz/(z1len+1e-30)-z1len)<=r2 * r2) | |
| end | |
| function containsOBB_Sphere(c1, x1, y1, z1, c2, r2) | |
| local cc = c1 - c2 | |
| local x1len, y1len, z1len = x1:length(), y1:length(), z1:length() | |
| return abs(cc:dot(x1))<=x1len*(x1len-r2) and abs(cc:dot(y1))<=y1len*(y1len-r2) and abs(cc:dot(z1))<=z1len*(z1len-r2) | |
| end | |
| function containsSphere_OBB(c1, r1, c2, x2, y2, z2) | |
| local cc = c1 - c2 | |
| local ccx1, cc_x1, y1z1, y1_z1 = cc+x2, cc-x2, y2+z2, y2-z2 | |
| return max((ccx1+y1z1):squaredLength(), (ccx1+y1_z1):squaredLength(), (ccx1-y1_z1):squaredLength(), (ccx1-y1z1):squaredLength(), | |
| (cc_x1+y1z1):squaredLength(), (cc_x1+y1_z1):squaredLength(), (cc_x1-y1_z1):squaredLength(), (cc_x1-y1z1):squaredLength())<=r1*r1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment