Search in sources :

Example 1 with Plane

use of maspack.matrix.Plane in project artisynth_core by artisynth.

the class BVIntersectorTest method testPlaneIntersection.

public void testPlaneIntersection(PolygonalMesh mesh, BVTree bvh, RigidTransform3d XMW) {
    Point3d center = new Point3d();
    double radius = bvh.getRadius();
    bvh.getCenter(center);
    mesh.setMeshToWorld(XMW);
    bvh.setBvhToWorld(XMW);
    Random rand = RandomGenerator.get();
    int numtrials = 100;
    for (int i = 0; i < numtrials; i++) {
        Plane plane = new Plane();
        plane.normal.setRandom();
        plane.offset = 3 * radius * (rand.nextDouble() - 0.5);
        testPlaneIntersection(mesh, bvh, plane);
    }
}
Also used : Random(java.util.Random) Plane(maspack.matrix.Plane) Point3d(maspack.matrix.Point3d)

Example 2 with Plane

use of maspack.matrix.Plane in project artisynth_core by artisynth.

the class BVIntersectorTest method intersectLeafNodes.

ArrayList<TriPlaneIntersection> intersectLeafNodes(BVTree bvh, Plane plane, BVIntersector intersector) {
    if (bvh.getBvhToWorld() != RigidTransform3d.IDENTITY) {
        plane = new Plane(plane);
        plane.inverseTransform(bvh.getBvhToWorld());
    }
    ArrayList<TriPlaneIntersection> intersections = new ArrayList<TriPlaneIntersection>();
    ArrayList<BVNode> nodes = new ArrayList<BVNode>();
    getAllIntersectingLeafNodes(nodes, bvh, plane);
    for (int i = 0; i < nodes.size(); i++) {
        intersector.intersectBoundingVolumeTriangles(intersections, nodes.get(i), plane);
    }
    for (TriPlaneIntersection isec : intersections) {
        for (int k = 0; k < isec.points.length; k++) {
            isec.points[k].transform(bvh.getBvhToWorld());
        }
    }
    return intersections;
}
Also used : Plane(maspack.matrix.Plane) ArrayList(java.util.ArrayList)

Example 3 with Plane

use of maspack.matrix.Plane in project artisynth_core by artisynth.

the class LineSegment method computeFocalPoint.

/**
 * Given a plane expressed in eye coordinates, compute a representative focal
 * point (in eye coordinates) for this plane, and return the distance
 * per-pixal for this focal point. Returning -1 means that the plane is
 * invisible.
 *
 * <p>
 * The method works by finding the centroid of the (clipped) polygon
 * associated with the grid boundary, as seen in screen coordinates. This
 * centroid is the projected back onto the plane.
 */
private double computeFocalPoint(Point3d focus, RigidTransform3d TGW, Renderer renderer) {
    RigidTransform3d XGridToEye = new RigidTransform3d();
    RigidTransform3d TWorldToEye = renderer.getViewMatrix();
    XGridToEye.mul(TWorldToEye, TGW);
    if (focus == null) {
        focus = new Point3d();
    }
    if (renderer.isOrthogonal()) {
        Plane plane = new Plane();
        plane.set(XGridToEye);
        computeFocalPoint(focus, plane, 0, 0, 1);
        return renderer.getViewPlaneWidth() / renderer.getScreenWidth();
    }
    double near = renderer.getViewPlaneDistance();
    double far = renderer.getFarPlaneDistance();
    double vw = renderer.getViewPlaneWidth();
    double vh = renderer.getViewPlaneHeight();
    // double fov = renderer.getFieldOfViewY();
    int height = renderer.getScreenHeight();
    double nearDistPerPixel = renderer.getViewPlaneHeight() / height;
    GridCentroidComputer newComp = new GridCentroidComputer(myMinSize, near, far);
    Point3d cent = new Point3d();
    if (!newComp.computeCentroid(cent, XGridToEye, vw, vh)) {
        return -1;
    }
    double zmax = newComp.getZmax();
    double zmin = newComp.getZmin();
    RotationMatrix3d R = XGridToEye.R;
    Plane plane = new Plane(new Vector3d(R.m02, R.m12, R.m22), new Point3d(XGridToEye.p));
    double s = plane.intersectLine(focus, cent, Point3d.ZERO);
    if (s == Double.POSITIVE_INFINITY) {
        focus.scale(-(zmin + zmax) / (2 * near), cent);
    }
    double zref = -focus.z;
    return zref / near * nearDistPerPixel;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Plane(maspack.matrix.Plane) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 4 with Plane

use of maspack.matrix.Plane in project artisynth_core by artisynth.

the class LineSegment method intersectBoundary.

private void intersectBoundary(ConvexPoly2d poly, RigidTransform3d XGridToEye, double nx, double ny, double nz, double d) {
    Plane plane = new Plane(nx, ny, nz, d);
    if (XGridToEye != RigidTransform3d.IDENTITY) {
        plane.inverseTransform(XGridToEye);
    }
    Vector3d u = new Vector3d();
    Point3d p = new Point3d();
    Plane polyPlane = new Plane(0, 0, 1, 0);
    if (polyPlane.intersectPlane(p, u, plane)) {
        poly.intersectHalfPlane(u.y, -u.x, p.x * u.y - p.y * u.x);
    }
}
Also used : Plane(maspack.matrix.Plane) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 5 with Plane

use of maspack.matrix.Plane in project artisynth_core by artisynth.

the class SegmentedPlanarCoupling method doProject.

private Plane doProject(RigidTransform3d TGD, RigidTransform3d TCD) {
    myTmp.set(TCD.p);
    Plane plane = closestPlane(myTmp);
    plane.project(myTmp, myTmp);
    if (TGD != null) {
        TGD.p.set(myTmp);
        TGD.R.set(TCD.R);
    }
    return plane;
}
Also used : Plane(maspack.matrix.Plane)

Aggregations

Plane (maspack.matrix.Plane)19 Point3d (maspack.matrix.Point3d)11 Vector3d (maspack.matrix.Vector3d)10 TetDesc (maspack.geometry.DistanceGrid.TetDesc)3 RigidTransform3d (maspack.matrix.RigidTransform3d)3 ArrayList (java.util.ArrayList)2 RotationMatrix3d (maspack.matrix.RotationMatrix3d)2 GLClipPlane (maspack.render.GL.GLClipPlane)2 RenderProps (maspack.render.RenderProps)2 FemElement3d (artisynth.core.femmodels.FemElement3d)1 FemMeshComp (artisynth.core.femmodels.FemMeshComp)1 FemMuscleModel (artisynth.core.femmodels.FemMuscleModel)1 MuscleBundle (artisynth.core.femmodels.MuscleBundle)1 FemMaterial (artisynth.core.materials.FemMaterial)1 LinearMaterial (artisynth.core.materials.LinearMaterial)1 MuscleMaterial (artisynth.core.materials.MuscleMaterial)1 SimpleForceMuscle (artisynth.core.materials.SimpleForceMuscle)1 MechModel (artisynth.core.mechmodels.MechModel)1 RigidBody (artisynth.core.mechmodels.RigidBody)1 Color (java.awt.Color)1