Search in sources :

Example 16 with Point3D

use of org.fxyz.geometry.Point3D in project FXyzLib by Birdasaur.

the class InterpolateBezier method calculateControlPoints.

private void calculateControlPoints() {
    if (isClosed) {
        List<Point3D> p1 = new ArrayList<>(numSplines);
        for (int j = 0; j < numSplines; j++) {
            p1.add(knots.get(j + 1).substract(j == 0 ? knots.get(numSplines - 1) : knots.get(j - 1)).multiply(1 / 3f).add(knots.get(j)));
        }
        for (int j = 0; j < numSplines; j++) {
            Point3D p2 = j == numSplines - 1 ? knots.get(0).multiply(2f).substract(p1.get(0)) : knots.get(j + 1).multiply(2f).substract(p1.get(j + 1));
            splines.add(new BezierHelper(knots.get(j), p1.get(j), p2, knots.get(j + 1)));
        }
    } else {
        for (int j = 0; j < numSplines; j++) {
            splines.add(new BezierHelper(knots.get(j), new Point3D(0f, 0f, 0f), new Point3D(0f, 0f, 0f), knots.get(j + 1)));
        }
        for (int i = 0; i < 3; i++) {
            double[] p1 = new double[numSplines];
            double[] p2 = new double[numSplines];
            double[] ca = new double[numSplines];
            double[] cb = new double[numSplines];
            double[] cc = new double[numSplines];
            double[] cr = new double[numSplines];
            cb[0] = 2d;
            cc[0] = 1d;
            cr[0] = i == 0 ? knots.get(0).x + 2d * knots.get(1).x : i == 1 ? knots.get(0).y + 2d * knots.get(1).y : knots.get(0).z + 2d * knots.get(1).z;
            for (int j = 1; j < numSplines - 1; j++) {
                ca[j] = 1d;
                cb[j] = 4d;
                cc[j] = 1d;
                cr[j] = i == 0 ? 4d * knots.get(j).x + 2d * knots.get(j + 1).x : i == 1 ? 4d * knots.get(j).y + 2d * knots.get(j + 1).y : 4d * knots.get(j).z + 2d * knots.get(j + 1).z;
            }
            ca[numSplines - 1] = 2d;
            cb[numSplines - 1] = 7d;
            cr[numSplines - 1] = i == 0 ? 8d * knots.get(numSplines - 1).x + knots.get(numSplines).x : i == 1 ? 8d * knots.get(numSplines - 1).y + knots.get(numSplines).y : 8d * knots.get(numSplines - 1).z + knots.get(numSplines).z;
            for (int j = 1; j < numSplines; j++) {
                double m = ca[j] / cb[j - 1];
                cb[j] -= m * cc[j - 1];
                cr[j] -= m * cr[j - 1];
            }
            p1[numSplines - 1] = cr[numSplines - 1] / cb[numSplines - 1];
            for (int j = numSplines - 2; j >= 0; j--) {
                p1[j] = (cr[j] - cc[j] * p1[j + 1]) / cb[j];
            }
            for (int j = 0; j < numSplines - 1; j++) {
                p2[j] = (i == 0 ? 2d * knots.get(j + 1).x : i == 1 ? 2d * knots.get(j + 1).y : 2d * knots.get(j + 1).z) - p1[j + 1];
            }
            p2[numSplines - 1] = ((i == 0 ? knots.get(numSplines).x : i == 1 ? knots.get(numSplines).y : knots.get(numSplines).z) + p1[numSplines - 1]) / 2d;
            for (int j = 0; j < numSplines; j++) {
                BezierHelper bez = splines.get(j);
                if (i == 0) {
                    bez.getPoints().get(1).x = (float) p1[j];
                    bez.getPoints().get(2).x = (float) p2[j];
                } else if (i == 1) {
                    bez.getPoints().get(1).y = (float) p1[j];
                    bez.getPoints().get(2).y = (float) p2[j];
                } else if (i == 2) {
                    bez.getPoints().get(1).z = (float) p1[j];
                    bez.getPoints().get(2).z = (float) p2[j];
                }
                splines.set(j, bez);
            }
        }
    }
// splines.forEach(System.out::println);
}
Also used : Point3D(org.fxyz.geometry.Point3D) ArrayList(java.util.ArrayList)

Example 17 with Point3D

use of org.fxyz.geometry.Point3D in project FXyzLib by Birdasaur.

the class KnotHelper method getKappa.

public double getKappa(double t) {
    // r'[t]
    Point3D dR = new Point3D((float) (-(p * (R + r * Math.cos(q * t)) * Math.sin(p * t)) - q * r * Math.cos(p * t) * Math.sin(q * t)), (float) (p * Math.cos(p * t) * (R + r * Math.cos(q * t)) - q * r * Math.sin(p * t) * Math.sin(q * t)), (float) (q * r * Math.cos(q * t)));
    // || r'[t] ||
    float nT = dR.magnitude();
    // r''[t]
    Point3D ddR = new Point3D((float) (-(q * q * r * Math.cos(p * t) * Math.cos(q * t)) - p * p * Math.cos(p * t) * (R + r * Math.cos(q * t)) + 2 * p * q * r * Math.sin(p * t) * Math.sin(q * t)), (float) (-(q * q * r * Math.cos(q * t) * Math.sin(p * t)) - p * p * (R + r * Math.cos(q * t)) * Math.sin(p * t) - 2 * p * q * r * Math.cos(p * t) * Math.sin(q * t)), (float) (-(q * q * r * Math.sin(q * t))));
    // || r''[t]xr'[t] ||
    float nddRxdR = ddR.crossProduct(dR).magnitude();
    // kappa[t] = || r''[t]xr'[t] || / || r'[t] ||^3
    return nddRxdR / (float) Math.pow(nT, 3d);
}
Also used : Point3D(org.fxyz.geometry.Point3D)

Example 18 with Point3D

use of org.fxyz.geometry.Point3D in project FXyzLib by Birdasaur.

the class KnotHelper method getTrihedron.

/*
    t [0,<=2Pi]
    */
private Point3D[] getTrihedron(double t) {
    // r[t]
    Point3D vR = new Point3D((float) (Math.cos(p * t) * (R + r * Math.cos(q * t))), (float) ((R + r * Math.cos(q * t)) * Math.sin(p * t)), (float) (r * Math.sin(q * t)));
    // r'[t]
    Point3D dR = new Point3D((float) (-(p * (R + r * Math.cos(q * t)) * Math.sin(p * t)) - q * r * Math.cos(p * t) * Math.sin(q * t)), (float) (p * Math.cos(p * t) * (R + r * Math.cos(q * t)) - q * r * Math.sin(p * t) * Math.sin(q * t)), (float) (q * r * Math.cos(q * t)));
    // || r'[t] ||
    float nT = dR.magnitude();
    // r''[t]
    Point3D ddR = new Point3D((float) (-(q * q * r * Math.cos(p * t) * Math.cos(q * t)) - p * p * Math.cos(p * t) * (R + r * Math.cos(q * t)) + 2 * p * q * r * Math.sin(p * t) * Math.sin(q * t)), (float) (-(q * q * r * Math.cos(q * t) * Math.sin(p * t)) - p * p * (R + r * Math.cos(q * t)) * Math.sin(p * t) - 2 * p * q * r * Math.cos(p * t) * Math.sin(q * t)), (float) (-(q * q * r * Math.sin(q * t))));
    // (|| r'[t] ||^2)'[t]
    float dn = (float) (-2 * p * p * q * r * (R + r * Math.cos(q * t)) * Math.sin(q * t));
    // T'[t]=r''[t]/||r't||-r'[t]*(|| r'[t] ||^2)'[t]/2/|| r'[t] ||^3
    Point3D dT = ddR.multiply(1f / nT).substract(dR.multiply(dn / ((float) (Math.pow(nT, 3d) * 2d))));
    // T[t]=r'[t]/||r'[t]||
    Point3D T = dR.normalize();
    // N[t]=T'[t]/||T'[t]||
    Point3D N = dT.normalize();
    // B[t]=T[t]xN[t]/||T[t]xN[t]||
    Point3D B = T.crossProduct(N).normalize();
    // R,N,B
    return new Point3D[] { vR, N, B };
}
Also used : Point3D(org.fxyz.geometry.Point3D)

Example 19 with Point3D

use of org.fxyz.geometry.Point3D in project FXyzLib by Birdasaur.

the class SpringHelper method getTrihedron.

/*
    t [0,<=2Pi]
    */
private Point3D[] getTrihedron(double t) {
    // r[t]
    Point3D vR = new Point3D((float) (R * Math.cos(t)), (float) (R * Math.sin(t)), (float) (h * t));
    // r'[t]
    Point3D dR = new Point3D((float) (-R * Math.sin(t)), (float) (R * Math.cos(t)), (float) (h));
    // || r'[t] ||
    float nT = dR.magnitude();
    // r''[t]
    Point3D ddR = new Point3D((float) (-R * Math.cos(t)), (float) (-R * Math.sin(t)), (float) (0));
    // (|| r'[t] ||^2)'[t]
    float dn = 0f;
    // T'[t]=r''[t]/||r't||-r'[t]*(|| r'[t] ||^2)'[t]/2/|| r'[t] ||^3
    Point3D dT = ddR.multiply(1f / nT).substract(dR.multiply(dn / ((float) (Math.pow(nT, 3d) * 2d))));
    // T[t]=r'[t]/||r'[t]||
    Point3D T = dR.normalize();
    // N[t]=T'[t]/||T'[t]||
    Point3D N = dT.normalize();
    // B[t]=T[t]xN[t]/||T[t]xN[t]||
    Point3D B = T.crossProduct(N).normalize();
    // R,N,B
    return new Point3D[] { vR, N, B };
}
Also used : Point3D(org.fxyz.geometry.Point3D)

Example 20 with Point3D

use of org.fxyz.geometry.Point3D in project FXyzLib by Birdasaur.

the class Link method solve.

/* Option 2
        // Pseudo-code to satisfy (C2)
        delta = x2-x1;
        deltalength = sqrt(delta*delta);
        diff = (deltalength-restlength)
              /(deltalength*(invmass1+invmass2));
        x1 -= invmass1*delta*diff;
        x2 += invmass2*delta*diff;
    */
@Override
public void solve() {
    // calculate the distance between the two PointMasss
    Point3D diff = new Point3D(p1.getPosition().x - p2.getPosition().x, p1.getPosition().y - p2.getPosition().y, p1.getPosition().z - p2.getPosition().z);
    double d = diff.magnitude();
    double difference = (distance - d) / d;
    double im1 = 1 / p1.getMass();
    double im2 = 1 / p2.getMass();
    double scalarP1 = (im1 / (im1 + im2)) * stiffness;
    double scalarP2 = stiffness - scalarP1;
    synchronized (this) {
        p1.position.x += ((float) (diff.x * scalarP1 * difference));
        p1.position.y += ((float) (diff.y * scalarP1 * difference));
        p1.position.z += ((float) (diff.z * scalarP1 * difference));
        p2.position.x -= ((float) (diff.x * scalarP2 * difference));
        p2.position.y -= ((float) (diff.y * scalarP2 * difference));
        p2.position.z -= ((float) (diff.z * scalarP2 * difference));
    }
}
Also used : Point3D(org.fxyz.geometry.Point3D)

Aggregations

Point3D (org.fxyz.geometry.Point3D)48 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 List (java.util.List)12 Face3 (org.fxyz.geometry.Face3)12 Collectors (java.util.stream.Collectors)10 IntStream (java.util.stream.IntStream)10 Group (javafx.scene.Group)10 Translate (javafx.scene.transform.Translate)10 ArrayList (java.util.ArrayList)9 Point2D (javafx.geometry.Point2D)9 PerspectiveCamera (javafx.scene.PerspectiveCamera)9 Scene (javafx.scene.Scene)9 KeyCode (javafx.scene.input.KeyCode)9 TriangleMesh (javafx.scene.shape.TriangleMesh)9 Rotate (javafx.scene.transform.Rotate)9 PointLight (javafx.scene.PointLight)8 MouseEvent (javafx.scene.input.MouseEvent)8 DoubleProperty (javafx.beans.property.DoubleProperty)7 IntegerProperty (javafx.beans.property.IntegerProperty)7 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)7