Java Code Examples for toxi.geom.Vec3D#set()

The following examples show how to use toxi.geom.Vec3D#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DepthAnalysis.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Compute the normal of a point.
 * @param neighbours
 * @param normal
 * @return 
 */
private boolean tryComputeLarge(Vec3D[] neighbours, Vec3D normal) {
    if (neighbours[Connexity.TOPLEFT] != null
            && neighbours[Connexity.TOPRIGHT] != null
            && neighbours[Connexity.BOTLEFT] != null
            && neighbours[Connexity.BOTRIGHT] != null) {

        Vec3D n1 = computeNormal(
                neighbours[Connexity.TOPLEFT],
                neighbours[Connexity.TOPRIGHT],
                neighbours[Connexity.BOTLEFT]);

        Vec3D n2 = computeNormal(
                neighbours[Connexity.BOTLEFT],
                neighbours[Connexity.TOPRIGHT],
                neighbours[Connexity.BOTRIGHT]);
        normal.set(n1.add(n2));
        return true;
    }
    return false;
}
 
Example 2
Source File: DepthAnalysis.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @param neighbours
 * @param normal
 * @return 
 */
private boolean tryComputeMediumSquare(Vec3D[] neighbours, Vec3D normal) {
    // small square around the point
    if (neighbours[Connexity.LEFT] != null
            && neighbours[Connexity.TOP] != null
            && neighbours[Connexity.RIGHT] != null
            && neighbours[Connexity.BOT] != null) {

        Vec3D n1 = computeNormal(
                neighbours[Connexity.LEFT],
                neighbours[Connexity.TOP],
                neighbours[Connexity.RIGHT]);

        Vec3D n2 = computeNormal(
                neighbours[Connexity.LEFT],
                neighbours[Connexity.RIGHT],
                neighbours[Connexity.BOT]);
        normal.set(n1.add(n2));
        return true;
    }
    return false;
}
 
Example 3
Source File: NurbsCreator.java    From toxiclibs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void lineIntersect3D(Vec3D p0, Vec3D t0, Vec3D p2, Vec3D t2,
        Vec3D out0, Vec3D out2) {
    Vec3D v02 = p0.sub(p2);

    double a = t0.dot(t0);
    double b = t0.dot(t2);
    double c = t2.dot(t2);
    double d = t0.dot(v02);
    double e = t2.dot(v02);
    double denom = a * c - b * b;

    double mu0, mu2;

    if (denom < MathUtils.EPS) {
        mu0 = 0;
        mu2 = b > c ? d / b : e / c;
    } else {
        mu0 = (b * e - c * d) / denom;
        mu2 = (a * e - b * d) / denom;
    }

    out0.set(t0.scale((float) mu0).addSelf(p0));
    out2.set(t2.scale((float) mu2).addSelf(p2));
}
 
Example 4
Source File: SphereTest.java    From toxiclibs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testIsInSphere() {
    Vec3D p = new Vec3D(0, -10, 0);
    Sphere s = new Sphere(new Vec3D(), 10);
    assertEquals(s.containsPoint(p), true);
    p.set(0, 10.1f, 0);
    assertEquals(s.containsPoint(p), false);
}
 
Example 5
Source File: AABBTest.java    From toxiclibs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testAABBNormal() {
    AABB box = new AABB(new Vec3D(100, 100, 100), new Vec3D(100, 100, 100));
    Vec3D p = new Vec3D(100, 300, 100);
    assertEquals(Vec3D.Y_AXIS, box.getNormalForPoint(p));
    p.set(100, -300, 100);
    assertEquals(Vec3D.Y_AXIS.getInverted(), box.getNormalForPoint(p));
    p.set(300, 100, 100);
    assertEquals(Vec3D.X_AXIS, box.getNormalForPoint(p));
    p.set(-300, 100, 100);
    assertEquals(Vec3D.X_AXIS.getInverted(), box.getNormalForPoint(p));
    p.set(100, 100, 300);
    assertEquals(Vec3D.Z_AXIS, box.getNormalForPoint(p));
    p.set(100, 100, -300);
    assertEquals(Vec3D.Z_AXIS.getInverted(), box.getNormalForPoint(p));
}
 
Example 6
Source File: DepthAnalysis.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Smallest unit of normal computation.
 * @param neighbours
 * @param point
 * @param normal
 * @return 
 */
private boolean tryComputeOneTriangle(Vec3D[] neighbours, Vec3D point, Vec3D normal) {
    // One triangle only. 
    // Left. 
    if (neighbours[Connexity.LEFT] != null) {
        if (neighbours[Connexity.TOP] != null) {
            normal.set(computeNormal(
                    neighbours[Connexity.LEFT],
                    neighbours[Connexity.TOP],
                    point));
            return true;
        } else {
            if (neighbours[Connexity.BOT] != null) {
                normal.set(computeNormal(
                        neighbours[Connexity.LEFT],
                        point,
                        neighbours[Connexity.BOT]));
                return true;
            }
        }
    } else {

        if (neighbours[Connexity.RIGHT] != null) {
            if (neighbours[Connexity.TOP] != null) {
                normal.set(computeNormal(
                        neighbours[Connexity.TOP],
                        neighbours[Connexity.RIGHT],
                        point));
                return true;
            } else {
                if (neighbours[Connexity.BOT] != null) {
                    normal.set(computeNormal(
                            neighbours[Connexity.RIGHT],
                            neighbours[Connexity.BOT],
                            point));
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 7
Source File: NurbsCreator.java    From toxiclibs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void pointToLine3D(ReadonlyVec3D p, ReadonlyVec3D t,
        Vec3D top, Vec3D out) {
    Vec3D dir = top.sub(p);
    float hyp = dir.magnitude();
    out.set(p.add(t.scale(t.dot(dir.normalize()) * hyp)));
}
 
Example 8
Source File: SurfaceMeshBuilder.java    From toxiclibs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Mesh3D createMesh(Mesh3D mesh, int res, float size, boolean isClosed) {
    if (mesh == null) {
        mesh = new TriangleMesh();
    }
    Vec3D a = new Vec3D();
    Vec3D b = new Vec3D();
    Vec3D pa = new Vec3D(), pb = new Vec3D();
    Vec3D a0 = new Vec3D(), b0 = new Vec3D();
    int phiRes = function.getPhiResolutionLimit(res);
    float phiRange = function.getPhiRange();
    int thetaRes = function.getThetaResolutionLimit(res);
    float thetaRange = function.getThetaRange();
    float pres = 1f / phiRes;
    float tres = 1f / thetaRes;
    float ires = 1f / res;
    Vec2D pauv = new Vec2D();
    Vec2D pbuv = new Vec2D();
    Vec2D auv = new Vec2D();
    Vec2D buv = new Vec2D();
    for (int p = 0; p < phiRes; p++) {
        float phi = p * phiRange * ires;
        float phiNext = (p + 1) * phiRange * ires;
        for (int t = 0; t <= thetaRes; t++) {
            float theta;
            theta = t * thetaRange * ires;
            a = function.computeVertexFor(a, phiNext, theta)
                    .scaleSelf(size);
            auv.set(t * tres, 1 - (p + 1) * pres);
            b = function.computeVertexFor(b, phi, theta).scaleSelf(size);
            buv.set(t * tres, 1 - p * pres);
            if (b.equalsWithTolerance(a, 0.0001f)) {
                b.set(a);
            }
            if (t > 0) {
                if (t == thetaRes && isClosed) {
                    a.set(a0);
                    b.set(b0);
                }
                mesh.addFace(pa, pb, a, pauv.copy(), pbuv.copy(),
                        auv.copy());
                mesh.addFace(pb, b, a, pbuv.copy(), buv.copy(), auv.copy());
            } else {
                a0.set(a);
                b0.set(b);
            }
            pa.set(a);
            pb.set(b);
            pauv.set(auv);
            pbuv.set(buv);
        }
    }
    return mesh;
}