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

The following examples show how to use toxi.geom.Vec3D#sub() . 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: 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 3
Source File: DLAParticle.java    From toxiclibs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void update(Vec3D target) {
    Vec3D d = target.sub(this);
    if (d.magnitude() > escapeRadius) {
        set(opos);
        reorientate();
        d = target.sub(this);
    }
    Vec3D ndir = d.getNormalizedTo(searchSpeed);
    dir.interpolateToSelf(ndir, particleSpeed);
    addSelf(dir);
}
 
Example 4
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)));
}