use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class PolygonalMesh method extendOpenEdges.
/**
* Extends the first open edge loop found.
*
* @param amount
* The amount to extend it by.
*/
public void extendOpenEdges(double amount) {
// Vertex3d v0;
HalfEdge he0 = null;
boolean found = false;
for (Object fo : myFaces) {
Face f = (Face) fo;
he0 = f.he0;
do {
if (isOpen(he0)) {
found = true;
break;
}
he0 = he0.next;
} while (he0 != f.he0);
if (found)
break;
}
Vector3d i = new Vector3d(), j = new Vector3d();
HalfEdge he = he0;
ArrayList<Vertex3d> iverts = new ArrayList<Vertex3d>(), overts = new ArrayList<Vertex3d>();
do {
HalfEdgeNode hen = he.tail.getIncidentHedges();
while (hen != null) {
if (isOpen(hen.he)) {
break;
}
hen = hen.next;
}
he.computeUnitVec(i);
hen.he.computeUnitVec(j);
double angleFactor = 1.0 - i.angle(j) / Math.PI;
i.add(j);
i.cross(he.face.getNormal());
i.normalize();
Point3d p = new Point3d();
p.scaledAdd(amount * angleFactor, i, he.tail.pnt);
iverts.add(he.tail);
overts.add(addVertex(p));
he = hen.he;
} while (he != he0);
Vertex3d lastiv = iverts.get(iverts.size() - 1), lastov = overts.get(overts.size() - 1);
for (int v = 0; v < iverts.size(); v++) {
Vertex3d iv = iverts.get(v), ov = overts.get(v);
addFace(new int[] { lastiv.idx, iv.idx, ov.idx });
addFace(new int[] { ov.idx, lastov.idx, lastiv.idx });
lastiv = iv;
lastov = ov;
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class PolygonalMesh method computePrincipalAxes.
public static RigidTransform3d computePrincipalAxes(PolygonalMesh mesh) {
Vector3d mov1 = new Vector3d();
Vector3d mov2 = new Vector3d();
Vector3d pov = new Vector3d();
double vol = mesh.computeVolumeIntegrals(mov1, mov2, pov);
double mass = vol;
Point3d cov = new Point3d();
// center of volume
cov.scale(1.0 / vol, mov1);
// [c], skew symmetric
Matrix3d covMatrix = new Matrix3d(0, -cov.z, cov.y, cov.z, 0, -cov.x, -cov.y, cov.x, 0);
// J
Matrix3d J = new Matrix3d((mov2.y + mov2.z), -pov.z, -pov.y, -pov.z, (mov2.x + mov2.z), -pov.x, -pov.y, -pov.x, (mov2.x + mov2.y));
// Jc = J + m[c][c]
Matrix3d Jc = new Matrix3d();
Jc.mul(covMatrix, covMatrix);
Jc.scale(mass);
Jc.add(J);
// Compute eigenvectors and eigenvlaues of Jc
SymmetricMatrix3d JcSymmetric = new SymmetricMatrix3d(Jc);
Vector3d lambda = new Vector3d();
Matrix3d U = new Matrix3d();
JcSymmetric.getEigenValues(lambda, U);
// Construct the rotation matrix
RotationMatrix3d R = new RotationMatrix3d();
R.set(U);
lambda.absolute();
if (lambda.x > lambda.y && lambda.z > lambda.y) {
R.rotateZDirection(new Vector3d(R.m01, R.m11, R.m21));
} else if (lambda.x > lambda.z && lambda.y > lambda.z) {
R.rotateZDirection(new Vector3d(R.m00, R.m10, R.m20));
}
return (new RigidTransform3d(cov, R));
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class NURBSObject method drawControlPoints.
protected void drawControlPoints(Renderer renderer, RenderProps props, int flags) {
Point3d tmp = new Point3d();
boolean selecting = renderer.isSelecting();
for (int i = 0; i < myCtrlPnts.size(); i++) {
if (selecting) {
renderer.beginSelectionQuery(i);
drawControlPoint(renderer, props, i, tmp);
renderer.endSelectionQuery();
} else {
drawControlPoint(renderer, props, i, tmp);
}
}
renderer.setPointSize(1);
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class OBB method computeBoundsFromConvexHullPoints.
// protected void setUsingConvexHullOfPoints (
// double[] pnts, int npnts, double margin) {
//
// Matrix3d C = new Matrix3d();
// Point3d cent = new Point3d();
//
// quickhull3d.Point3d[] hullPnts =
// computeConvexHullAndCovariance (C, cent, pnts, npnts);
//
// setTransform (C, cent);
// Point3d max = new Point3d (-INF, -INF, -INF);
// Point3d min = new Point3d (INF, INF, INF);
// computeBoundsFromConvexHullPoints (min, max, hullPnts, hullPnts.length);
// setWidthsAndCenter (min, max, margin);
// }
//
private void computeBoundsFromConvexHullPoints(Point3d min, Point3d max, quickhull3d.Point3d[] pnts, int num) {
Vector3d xpnt = new Point3d();
for (int i = 0; i < num; i++) {
xpnt.set(pnts[i].x, pnts[i].y, pnts[i].z);
xpnt.inverseTransform(myX);
xpnt.updateBounds(min, max);
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class OBB method set.
public void set(Boundable[] elems, int num, double margin, Method method) {
Matrix3d C = new Matrix3d();
Point3d cent = new Point3d();
Point3d max = new Point3d(-INF, -INF, -INF);
Point3d min = new Point3d(INF, INF, INF);
switch(method) {
case ConvexHull:
{
HashedPointSet pointSet = createPointSetForOBB(elems, num);
quickhull3d.Point3d[] hullPnts = computeConvexHullAndCovariance(C, cent, pointSet.getPointsAsDoubleArray(), pointSet.size());
setTransform(C, cent);
computeBoundsFromConvexHullPoints(min, max, hullPnts, hullPnts.length);
break;
}
case Covariance:
{
computeCovarianceFromElements(C, cent, elems, num);
setTransform(C, cent);
computeBoundsFromElements(min, max, elems, num);
break;
}
case Points:
{
HashedPointSet pointSet = createPointSetForOBB(elems, num);
Point3d[] pnts = pointSet.getPoints();
computeCovarianceFromPoints(C, cent, pnts);
setTransform(C, cent);
computeBoundsFromPoints(min, max, pnts);
break;
}
default:
throw new InternalErrorException("Unimplemented method " + method);
}
setWidthsAndCenter(min, max, margin);
}
Aggregations