Search in sources :

Example 26 with Vector3d

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

the class DistanceGrid method fitToFeaturesOBB.

public void fitToFeaturesOBB(Collection<List<? extends Feature>> featureSets, double marginFrac, int maxRes) {
    Vector3d widths = new Vector3d();
    RigidTransform3d TCL = new RigidTransform3d();
    fitOBB(widths, TCL, marginFrac, featureSets, OBB.Method.Covariance);
    if (maxRes > 0) {
        double cwidth = widths.maxElement() / maxRes;
        Vector3i resolution = new Vector3i((int) (Math.ceil(widths.x / cwidth)), (int) (Math.ceil(widths.y / cwidth)), (int) (Math.ceil(widths.z / cwidth)));
        setResolution(resolution);
        // update widths and origin to accommodate uniform cell width
        widths.set(resolution);
        widths.scale(cwidth);
    }
    setWidths(widths);
    setCenterAndOrientation(TCL);
}
Also used : Vector3d(maspack.matrix.Vector3d) Vector3i(maspack.matrix.Vector3i)

Example 27 with Vector3d

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

the class DistanceGrid method render.

public void render(Renderer renderer, RenderProps props, int flags) {
    if (myTLocalToWorld != null) {
        renderer.pushModelMatrix();
        renderer.mulModelMatrix(myTLocalToWorld);
    }
    Vector3d widths = getCellWidths();
    double r = 0.05 * widths.minElement();
    RenderObject rob = myRob;
    if (rob != null) {
        if (props.getPointStyle() == PointStyle.POINT) {
            if (props.getPointSize() != 0) {
                renderer.setColor(props.getPointColor());
                renderer.drawPoints(rob, PointStyle.POINT, props.getPointSize());
            }
        } else {
            if (props.getPointRadius() > 0) {
                renderer.setColor(props.getPointColor());
                renderer.drawPoints(rob, props.getPointStyle(), props.getPointRadius());
            }
        }
        if (props.getLineStyle() == LineStyle.LINE) {
            if (props.getLineWidth() != 0) {
                rob.lineGroup(NORMAL_GROUP);
                renderer.setColor(props.getLineColor());
                renderer.drawLines(rob, LineStyle.LINE, props.getLineWidth());
            }
        } else {
            if (props.getLineRadius() > 0) {
                rob.lineGroup(NORMAL_GROUP);
                renderer.setColor(props.getLineColor());
                renderer.drawLines(rob, props.getLineStyle(), props.getLineRadius());
            }
        }
        if (myDrawEdges && rob.numLineGroups() == 2) {
            if (props.getEdgeWidth() > 0) {
                rob.lineGroup(EDGE_GROUP);
                renderer.setColor(props.getEdgeOrLineColorF());
                renderer.drawLines(rob, LineStyle.LINE, props.getEdgeWidth());
            }
        }
    }
    if (myTLocalToWorld != null) {
        renderer.popModelMatrix();
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) RenderObject(maspack.render.RenderObject)

Example 28 with Vector3d

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

the class DistanceGrid method getQuadTet.

/**
 * Used for debugging
 */
public TetDesc getQuadTet(Point3d point) {
    Vector3d coords = new Vector3d();
    Vector3i vidx = new Vector3i();
    if (getQuadCellCoords(coords, vidx, point, myQuadGridToLocal) == -1) {
        return null;
    }
    double dx = coords.x;
    double dy = coords.y;
    double dz = coords.z;
    return new TetDesc(vidx, TetID.findSubTet(dx, dy, dz));
}
Also used : Vector3d(maspack.matrix.Vector3d) Vector3i(maspack.matrix.Vector3i)

Example 29 with Vector3d

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

the class LineSegment method nearestPointParameters.

/**
 * For two lines defined by the points <code>p0, p1</code>
 * and <code>pa, pb</code>, computes the parameters
 * <code>s</code> and <code>t</code> such that
 * <pre>
 * ps = (1-s) p0 + s p1
 * pt = (1-t) pa + t pb
 * </pre>
 * are the points on the two lines which are nearest to
 * each other. If the two lines are parallel, <code>s</code>
 * and <code>t</code> are both set to 0 and the method returns
 * <code>false</code>.
 *
 * @param params returns the values of s and t
 * @param p0 first point defining the first line
 * @param p1 second point defining the first line
 * @param pa first point defining the second line
 * @param pb second point defining the second line
 * @return returns <code>true</code> if the lines are
 * not parallel and <code>false</code> if they are
 */
public static boolean nearestPointParameters(double[] params, Point3d p0, Point3d p1, Point3d pa, Point3d pb) {
    Vector3d u01 = new Vector3d();
    Vector3d uab = new Vector3d();
    u01.sub(p1, p0);
    double len01 = u01.norm();
    u01.scale(1 / len01);
    uab.sub(pb, pa);
    double lenab = uab.norm();
    uab.scale(1 / lenab);
    Vector3d tmp = new Vector3d();
    tmp.cross(u01, uab);
    double denom = tmp.normSquared();
    if (denom < 100 * DOUBLE_PREC) {
        params[0] = 0;
        params[1] = 0;
        return false;
    } else {
        tmp.sub(p0, pa);
        double k1 = -u01.dot(tmp);
        double k2 = uab.dot(tmp);
        double dotU = u01.dot(uab);
        params[0] = (k1 + dotU * k2) / (len01 * denom);
        params[1] = (dotU * k1 + k2) / (lenab * denom);
        return true;
    }
}
Also used : Vector3d(maspack.matrix.Vector3d)

Example 30 with Vector3d

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

the class LineSegment method projectionParameter.

/**
 * Computes the projection parameter of a point <code>px</code>
 * with respect to a line defined by points <code>p0</code> and
 * <code>p1</code>. This is the value <i>s</i> such that
 * <pre>
 * pp = (1-s) p0 + s p1
 * </pre>
 * gives the projection of <code>px-p0</code> onto the line. If
 * <code>p0</code> and <code>p1</code> are identical, the
 * method returns positive infinity.
 *
 * @param p0 first point defining the line
 * @param p1 second point defining the libe
 * @param px point for which the project parameter should be computed
 * @return parameter s which projects px onto the line
 */
public static double projectionParameter(Point3d p0, Point3d p1, Point3d px) {
    Vector3d del10 = new Vector3d();
    Vector3d delx0 = new Vector3d();
    del10.sub(p1, p0);
    delx0.sub(px, p0);
    double len10Sqr = del10.normSquared();
    if (len10Sqr == 0) {
        return Double.POSITIVE_INFINITY;
    } else {
        return del10.dot(delx0) / len10Sqr;
    }
}
Also used : Vector3d(maspack.matrix.Vector3d)

Aggregations

Vector3d (maspack.matrix.Vector3d)441 Point3d (maspack.matrix.Point3d)128 RigidTransform3d (maspack.matrix.RigidTransform3d)56 ArrayList (java.util.ArrayList)38 Matrix3d (maspack.matrix.Matrix3d)32 RotationMatrix3d (maspack.matrix.RotationMatrix3d)30 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)24 PolygonalMesh (maspack.geometry.PolygonalMesh)23 Vertex3d (maspack.geometry.Vertex3d)23 Face (maspack.geometry.Face)20 AxisAngle (maspack.matrix.AxisAngle)19 Vector3i (maspack.matrix.Vector3i)19 Point (artisynth.core.mechmodels.Point)18 RenderProps (maspack.render.RenderProps)17 VectorNd (maspack.matrix.VectorNd)15 AffineTransform3d (maspack.matrix.AffineTransform3d)14 IOException (java.io.IOException)13 Vector2d (maspack.matrix.Vector2d)11 Plane (maspack.matrix.Plane)10 GLViewer (maspack.render.GL.GLViewer)9