use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class CutPlaneProbe method setOrientation.
/**
* Sets the orientation of the display
*/
public void setOrientation(AxisAngle axisAng) {
RigidTransform3d X = new RigidTransform3d(XGridToWorld);
X.R.setAxisAngle(axisAng);
setGridToWorld(X);
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class CutPlaneProbe method setPosition.
/**
* Sets the 3D position of the centre of the display
*/
public void setPosition(Point3d pos) {
RigidTransform3d X = new RigidTransform3d(XGridToWorld);
X.p.set(pos);
setGridToWorld(X);
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class PointDistributor method getTightOBB.
public static OBB getTightOBB(Point3d[] pnts, RigidTransform3d principal) {
Vector3d[] axis = new Vector3d[3];
double[][] projBounds = new double[3][2];
for (int i = 0; i < 3; i++) {
axis[i] = new Vector3d();
principal.R.getColumn(i, axis[i]);
}
Vector3d p = principal.p;
// loop through all nodes, projecting onto axes
for (int i = 0; i < pnts.length; i++) {
for (int j = 0; j < 3; j++) {
Vector3d vec = new Vector3d();
vec.sub(pnts[i], p);
double d = vec.dot(axis[j]);
if (d < projBounds[j][0]) {
projBounds[j][0] = d;
} else if (d > projBounds[j][1]) {
projBounds[j][1] = d;
}
}
// end looping through axes
}
// end looping over vertices
// construct bounds
Point3d c = new Point3d(0, 0, 0);
Vector3d widths = new Vector3d();
for (int i = 0; i < 3; i++) {
c.set(i, 0);
widths.set(i, projBounds[i][1] - projBounds[i][0]);
c.set(i, p.get(i) + (projBounds[i][0] + projBounds[i][1]) / 2);
}
RigidTransform3d trans = new RigidTransform3d(c, principal.R);
OBB obb = new OBB(widths, trans);
return obb;
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class PointDistributor method getSphericalMidpointCubature.
public static CubaturePoint3d[] getSphericalMidpointCubature(Point3d center, double radius, int nR, int nPhi, int nTheta, Vector3d axis) {
CubaturePoint3d[] pnts = new CubaturePoint3d[nR * nPhi * nTheta];
double dr = radius / nR;
double dphi = 2 * Math.PI / nPhi;
double dtheta = Math.PI / nTheta;
RigidTransform3d trans = new RigidTransform3d();
if (axis != null) {
RotationMatrix3d R = new RotationMatrix3d();
R.rotateZDirection(axis);
trans.setRotation(R);
}
trans.setTranslation(center);
double r, phi, theta;
int idx = 0;
for (int i = 0; i < nR; i++) {
for (int j = 0; j < nPhi; j++) {
for (int k = 0; k < nTheta; k++) {
r = i * dr + dr / 2;
phi = j * dphi + (i + k) * dphi / 2;
theta = k * dtheta + dtheta / 2;
pnts[idx] = new CubaturePoint3d();
pnts[idx].x = r * Math.cos(phi) * Math.sin(theta);
pnts[idx].y = r * Math.sin(phi) * Math.sin(theta);
pnts[idx].z = r * Math.cos(theta);
pnts[idx].w = spherePartialVolume(radius, r, dr, phi, dphi, theta, dtheta);
// transform
pnts[idx].transform(trans);
idx++;
}
}
}
return pnts;
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class PointDistributor method sphereGridFill.
// fills a mesh based on a regular grid of points
public static Point3d[] sphereGridFill(PolygonalMesh mesh, double r) {
ArrayList<Point3d> pnts = new ArrayList<Point3d>();
RigidTransform3d trans = getPrincipalAxes(mesh);
Point3d[] box = getTightBox(mesh, trans);
Point3d center = new Point3d(box[0]);
center.add(box[6]);
center.scale(0.5);
trans.setTranslation(center);
Vector3d l = new Vector3d(box[0]);
l.sub(box[6]);
l.inverseTransform(trans);
double alpha = 2 * Math.sqrt(2) * r;
int nx = (int) Math.ceil(l.x / alpha) + 1;
int ny = (int) Math.ceil(l.y / alpha) + 1;
int nz = (int) Math.ceil(l.z / alpha) + 1;
double xoffset = -(nx - 1) * alpha / 2;
double yoffset = -(ny - 1) * alpha / 2;
double zoffset = -(nz - 1) * alpha / 2;
BVTree bvh = mesh.getBVTree();
Vector2d coords = new Vector2d();
Point3d nearest = new Point3d();
BVFeatureQuery query = new BVFeatureQuery();
Point3d p;
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
double x = i * alpha + xoffset;
double y = j * alpha + yoffset;
double z = k * alpha + zoffset;
p = new Point3d(x, y, z);
p.transform(trans);
addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
}
}
}
return pnts.toArray(new Point3d[pnts.size()]);
}
Aggregations