Search in sources :

Example 1 with Point2d

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

the class NURBSCurve2d method evalPoints.

/**
 * Returns a set of points evaluated along the curve at intervals which are
 * evenly spaced with respect to the curve parameter.
 *
 * @param npnts
 * number of points to create
 * @return array of evaluated points
 */
public Point2d[] evalPoints(int npnts) {
    Point2d[] pnts = new Point2d[npnts];
    Point3d pnt3 = new Point3d();
    if (npnts == 1) {
        eval(pnt3, myUstart);
        pnts[0] = new Point2d(pnt3.x, pnt3.y);
    }
    for (int i = 0; i < npnts; i++) {
        eval(pnt3, myUstart + (myUend - myUstart) * i / (npnts - 1));
        pnts[i] = new Point2d(pnt3.x, pnt3.y);
    }
    return pnts;
}
Also used : Point2d(maspack.matrix.Point2d) Point3d(maspack.matrix.Point3d)

Example 2 with Point2d

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

the class Intersector2d method intersectLineLine.

public int intersectLineLine(Point2d c1, Vector2d v1, Point2d c2, Vector2d v2, ArrayList<Point2d> points) {
    int nAdded = 0;
    Vector2d n1 = new Vector2d(-v1.y, v1.x);
    Vector2d n2 = new Vector2d(-v2.y, v2.x);
    n1.normalize();
    n2.normalize();
    double b1 = c1.dot(n1);
    double b2 = c2.dot(n2);
    // denominator, if zero lines are parallel
    double d = n1.x * n2.y - n1.y * n2.x;
    if (Math.abs(d) < epsilon) {
        d = n1.dot(c2) - b1;
        // distance of c2 to line 1
        d = d / n1.norm();
        if (Math.abs(d) < epsilon) {
            // lines are colinear, so add both
            // add both points
            points.add(c1);
            points.add(c2);
            nAdded = 2;
        } else {
            nAdded = 0;
        }
    } else {
        double x = (n2.y * b1 - n1.y * b2) / d;
        double y = (-n2.x * b1 + n1.x * b2) / d;
        points.add(new Point2d(x, y));
        nAdded++;
    }
    return nAdded;
}
Also used : Vector2d(maspack.matrix.Vector2d) Point2d(maspack.matrix.Point2d)

Example 3 with Point2d

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

the class TriangleTessellator method getPoints.

/**
 * The final 2D points in the tessellation
 * @return 2D points
 */
public Point2d[] getPoints() {
    double[] coords = getPointCoords();
    int nump = coords.length / 2;
    Point2d[] pnts = new Point2d[nump];
    for (int i = 0; i < nump; i++) {
        pnts[i] = new Point2d(coords[2 * i], coords[2 * i + 1]);
    }
    return pnts;
}
Also used : Point2d(maspack.matrix.Point2d)

Example 4 with Point2d

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

the class DicomPlaneTextureContent method getTextureCoordinates.

/**
 * Texture coordinates, starting with the
 * bottom-left corner and working around clockwise.
 *
 * @return texture coordinates
 */
public Point2d[] getTextureCoordinates() {
    Point2d[] out = new Point2d[4];
    int w = res.x - 1;
    int h = res.y - 1;
    double tx1 = (double) rect.x() / w;
    double tx2 = ((double) rect.x() + rect.width() - 1) / w;
    double ty1 = (double) rect.y() / h;
    double ty2 = ((double) rect.y() + rect.height() - 1) / h;
    out[0] = new Point2d(tx1, ty1);
    out[1] = new Point2d(tx1, ty2);
    out[2] = new Point2d(tx2, ty2);
    out[3] = new Point2d(tx2, ty1);
    return out;
}
Also used : Point2d(maspack.matrix.Point2d)

Example 5 with Point2d

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

the class DicomTextureContent method getTextureCoordinates.

/**
 * Texture coordinates for a given plane ({@link #COL_ROW_PLANE},
 * {@link #ROW_SLICE_PLANE}, or {@link #COL_SLICE_PLANE}), starting with the
 * bottom-left corner and working around clockwise.
 *
 * @return texture coordinates
 */
public Point2d[] getTextureCoordinates(int plane) {
    Point2d[] out = new Point2d[4];
    Rectangle rect = rects[plane];
    int w = textureWidth - 1;
    int h = textureHeight - 1;
    double tx1 = (double) rect.x() / w;
    double tx2 = ((double) rect.x() + rect.width() - 1) / w;
    double ty1 = (double) rect.y() / h;
    double ty2 = ((double) rect.y() + rect.height() - 1) / h;
    out[0] = new Point2d(tx1, ty1);
    out[1] = new Point2d(tx1, ty2);
    out[2] = new Point2d(tx2, ty2);
    out[3] = new Point2d(tx2, ty1);
    return out;
}
Also used : Point2d(maspack.matrix.Point2d) Rectangle(maspack.util.Rectangle)

Aggregations

Point2d (maspack.matrix.Point2d)20 ArrayList (java.util.ArrayList)6 Point3d (maspack.matrix.Point3d)5 Vector2d (maspack.matrix.Vector2d)5 Vector3d (maspack.matrix.Vector3d)4 Font (java.awt.Font)3 Face (maspack.geometry.Face)3 BVNode (maspack.geometry.BVNode)2 Boundable (maspack.geometry.Boundable)2 Vertex3d (maspack.geometry.Vertex3d)2 RenderObject (maspack.render.RenderObject)2 HalfEdge (maspack.geometry.HalfEdge)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 Shading (maspack.render.Renderer.Shading)1 Rectangle (maspack.util.Rectangle)1