Search in sources :

Example 31 with Point3d

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

the class MeshFactory method createSphericalPolyline.

public static PolylineMesh createSphericalPolyline(double r, int nslices, int nlevels) {
    PolylineMesh mesh = new PolylineMesh();
    int[] lineIdxs = new int[nlevels - 1];
    int vtxIdx = 0;
    for (int j = 0; j < nslices; j++) {
        double the = 2 * Math.PI * (j / (double) nslices);
        double cthe = Math.cos(the);
        double sthe = Math.sin(the);
        for (int i = 1; i < nlevels; i++) {
            double phi = Math.PI / 2 - Math.PI * (i / (double) (nlevels));
            double cphi = Math.cos(phi);
            double sphi = Math.sin(phi);
            mesh.addVertex(new Point3d(r * cphi * cthe, r * cphi * sthe, r * sphi));
            lineIdxs[i - 1] = vtxIdx++;
        }
        mesh.addLine(lineIdxs);
    }
    return mesh;
}
Also used : Point3d(maspack.matrix.Point3d)

Example 32 with Point3d

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

the class MeshFactory method createQuadSphere.

public static PolygonalMesh createQuadSphere(double r, int nslices, int nlevels, double x, double y, double z, boolean addTextureCoords) {
    double tol = computeSphericalPointTolerance(r, 2 * Math.PI, Math.PI, nslices, nlevels);
    PolygonalMesh mesh = new PolygonalMesh();
    VertexMap vtxMap = new VertexMap(tol);
    RigidTransform3d XLM = new RigidTransform3d(x, y, z);
    addQuadSphericalSection(mesh, r, Math.PI, Math.PI, nslices, nlevels, XLM, vtxMap);
    if (addTextureCoords) {
        Point3d origin = new Point3d(x, y, z);
        computeTextureCoordsForSphere(mesh, origin, r, tol);
    }
    return mesh;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Point3d(maspack.matrix.Point3d)

Example 33 with Point3d

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

the class DistanceGridSurfCalc method findNearestFeature.

/**
 * Find the nearest feature on a tet to a point p0. eps is a tolerance
 * (in the range [0,1]) used to check the barycentric coordinates
 * of p0 to see if it is actually close to a feature. If it
 * is not, this method returns null.
 */
TetFeature findNearestFeature(TetDesc desc, Point3d p0Loc, double eps) {
    if (myTetBarycentricMats == null) {
        createTetBarycentricMats();
    }
    // convert p0Loc to quad grid coordinates, and the multiply by the
    // barycentric conversion matrix to get barycentric coordinates s1, s2,
    // s3. s0 is then given by s0 = 1 - s1 - s2 - s2.
    Point3d pc = new Point3d();
    Vector3d sv = new Vector3d();
    transformToQuadCell(pc, p0Loc, desc);
    myTetBarycentricMats[desc.myTetId.intValue()].mul(sv, pc);
    // code is a bit code describing which coordinates are close to 0
    int code = 0;
    if (Math.abs(1 - sv.get(0) - sv.get(1) - sv.get(2)) < eps) {
        code |= 0x01;
    }
    if (Math.abs(sv.get(0)) < eps) {
        code |= 0x02;
    }
    if (Math.abs(sv.get(1)) < eps) {
        code |= 0x04;
    }
    if (Math.abs(sv.get(2)) < eps) {
        code |= 0x08;
    }
    int[] nodes = desc.myTetId.getNodes();
    switch(code) {
        case 0x01:
            {
                return new TetFace(nodes[1], nodes[3], nodes[2]);
            }
        case 0x02:
            {
                return new TetFace(nodes[0], nodes[2], nodes[3]);
            }
        case 0x04:
            {
                return new TetFace(nodes[0], nodes[3], nodes[1]);
            }
        case 0x08:
            {
                return new TetFace(nodes[0], nodes[1], nodes[2]);
            }
        case 0x03:
            return new TetEdge(nodes[2], nodes[3]);
        case 0x05:
            return new TetEdge(nodes[1], nodes[3]);
        case 0x09:
            return new TetEdge(nodes[1], nodes[2]);
        case 0x06:
            return new TetEdge(nodes[0], nodes[3]);
        case 0x0a:
            return new TetEdge(nodes[0], nodes[2]);
        case 0x0c:
            return new TetEdge(nodes[0], nodes[1]);
        case 0x0e:
            return new TetNode(nodes[0]);
        case 0x0d:
            return new TetNode(nodes[1]);
        case 0x0b:
            return new TetNode(nodes[2]);
        case 0x07:
            return new TetNode(nodes[3]);
        default:
            {
                return null;
            }
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 34 with Point3d

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

the class DistanceGridSurfCalc method intersectTriangle.

void intersectTriangle(TetPlaneIntersection isect, TetDesc tdesc, Point3d[] vpnts, double[] dist, int i0, int i1, int i2, int i3) {
    int[] nodes = tdesc.myTetId.getNodes();
    int n0 = nodes[i0];
    Point3d p0 = vpnts[i0];
    double d0 = dist[i0];
    double EPS = 1e-8;
    double s1 = d0 / (d0 - dist[i1]);
    double s2 = d0 / (d0 - dist[i2]);
    double s3 = d0 / (d0 - dist[i3]);
    int numsmall = 0;
    if (s1 <= EPS) {
        numsmall++;
    }
    if (s2 <= EPS) {
        numsmall++;
    }
    if (s3 <= EPS) {
        numsmall++;
    }
    if (numsmall > 1) {
        isect.myNumSides = 0;
    }
    isect.myP0.combine(1 - s1, p0, s1, vpnts[i1]);
    isect.myP1.combine(1 - s2, p0, s2, vpnts[i2]);
    isect.myP2.combine(1 - s3, p0, s3, vpnts[i3]);
    isect.myNumSides = 3;
    isect.myCCW = d0 < 0 ? 1 : -1;
}
Also used : Point3d(maspack.matrix.Point3d)

Example 35 with Point3d

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

the class DistanceGridSurfCalc method getFeatureAdjacentTets.

protected int getFeatureAdjacentTets(TetDesc tdesc, TetFeature feat, Plane plane, HashSet<TetDesc> visited) {
    createConnectivityIfNecessary();
    Point3d[] vpnts = new Point3d[] { new Point3d(), new Point3d(), new Point3d(), new Point3d() };
    if (feat instanceof TetFace) {
        TetDesc adjDesc = myFaceTets.get((TetFace) feat);
        TetDesc adesc = new TetDesc(adjDesc);
        adesc.addOffset(tdesc);
        if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
            getVertexCoords(vpnts, adesc);
            TetPlaneIntersection isect = getIsect(0);
            if (intersectTetAndPlane(isect, adesc, vpnts, plane)) {
                return 1;
            }
        }
        return 0;
    } else {
        TetDesc[] adjDescs = null;
        if (feat instanceof TetNode) {
            adjDescs = myNodeTets.get(((TetNode) feat).getNode());
        } else {
            // feat instanceof TetEdge
            adjDescs = myEdgeTets.get((TetEdge) feat);
        }
        int numi = 0;
        for (int i = 0; i < adjDescs.length; i++) {
            TetDesc adesc = new TetDesc(adjDescs[i]);
            adesc.addOffset(tdesc);
            if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
                // different from that of tdesc
                if ((feat instanceof TetNode && !adesc.cellEquals(tdesc)) || (feat instanceof TetEdge && !adesc.equals(tdesc))) {
                    getVertexCoords(vpnts, adesc);
                    TetPlaneIntersection isect = getIsect(numi);
                    if (intersectTetAndPlane(isect, adesc, vpnts, plane)) {
                        numi++;
                    }
                }
            }
        }
        return numi;
    }
}
Also used : Point3d(maspack.matrix.Point3d) TetDesc(maspack.geometry.DistanceGrid.TetDesc)

Aggregations

Point3d (maspack.matrix.Point3d)464 Vector3d (maspack.matrix.Vector3d)128 ArrayList (java.util.ArrayList)59 RigidTransform3d (maspack.matrix.RigidTransform3d)48 Vertex3d (maspack.geometry.Vertex3d)35 Point (artisynth.core.mechmodels.Point)30 PolygonalMesh (maspack.geometry.PolygonalMesh)30 Face (maspack.geometry.Face)25 ReaderTokenizer (maspack.util.ReaderTokenizer)19 IOException (java.io.IOException)18 RotationMatrix3d (maspack.matrix.RotationMatrix3d)17 Vector2d (maspack.matrix.Vector2d)16 VectorNd (maspack.matrix.VectorNd)16 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)15 HashMap (java.util.HashMap)14 Muscle (artisynth.core.mechmodels.Muscle)13 FemNode3d (artisynth.core.femmodels.FemNode3d)12 Particle (artisynth.core.mechmodels.Particle)12 BufferedReader (java.io.BufferedReader)11 Plane (maspack.matrix.Plane)11