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

The following examples show how to use toxi.geom.Vec3D#dot() . 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: 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 2
Source File: TriangleMesh.java    From toxiclibs with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c, Vec3D n, Vec2D uvA,
        Vec2D uvB, Vec2D uvC) {
    Vertex va = checkVertex(a);
    Vertex vb = checkVertex(b);
    Vertex vc = checkVertex(c);
    if (va.id == vb.id || va.id == vc.id || vb.id == vc.id) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("ignorning invalid face: " + a + "," + b + "," + c);
        }
    } else {
        if (n != null) {
            Vec3D nc = va.sub(vc).crossSelf(va.sub(vb));
            if (n.dot(nc) < 0) {
                Vertex t = va;
                va = vb;
                vb = t;
            }
        }
        Face f = new Face(va, vb, vc, uvA, uvB, uvC);
        faces.add(f);
        numFaces++;
    }
    return this;
}
 
Example 3
Source File: MeshIntersector.java    From toxiclibs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private float intersectTriangle(Vec3D a, Vec3D b, Vec3D c, Vec3D ro,
        Vec3D dir) {
    Vec3D e1 = b.sub(a);
    Vec3D e2 = c.sub(a);
    Vec3D pvec = dir.cross(e2);
    float det = e1.dot(pvec);
    if (det > -EPS && det < EPS) {
        return -1;
    }
    float invDet = 1f / det;
    Vec3D tvec = ro.sub(a);
    float u = tvec.dot(pvec) * invDet;
    if (u < 0.0 || u > 1.0) {
        return -1;
    }
    Vec3D qvec = tvec.cross(e1);
    float v = dir.dot(qvec) * invDet;
    if (v < 0.0 || u + v > 1.0) {
        return -1;
    }
    float t = e2.dot(qvec) * invDet;
    return t;
}
 
Example 4
Source File: TriangleMesh.java    From toxiclibs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TriangleMesh faceOutwards() {
    computeCentroid();
    for (Face f : faces) {
        Vec3D n = f.getCentroid().sub(centroid);
        float dot = n.dot(f.normal);
        if (dot < 0) {
            f.flipVertexOrder();
        }
    }
    return this;
}
 
Example 5
Source File: WETriangleMesh.java    From toxiclibs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public WETriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c, Vec3D n,
        Vec2D uvA, Vec2D uvB, Vec2D uvC) {
    WEVertex va = checkVertex(a);
    WEVertex vb = checkVertex(b);
    WEVertex vc = checkVertex(c);
    if (va.id == vb.id || va.id == vc.id || vb.id == vc.id) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("ignorning invalid face: " + a + "," + b + "," + c);
        }
    } else {
        if (n != null) {
            Vec3D nc = va.sub(vc).crossSelf(va.sub(vb));
            if (n.dot(nc) < 0) {
                WEVertex t = va;
                va = vb;
                vb = t;
            }
        }
        WEFace f = new WEFace(va, vb, vc, uvA, uvB, uvC);
        faces.add(f);
        numFaces++;
        updateEdge(va, vb, f);
        updateEdge(vb, vc, f);
        updateEdge(vc, va, f);
    }
    return this;
}