Search in sources :

Example 1 with Matrix3D

use of org.jwildfire.base.mathlib.VecMathLib.Matrix3D in project JWildfire by thargor6.

the class DLA3DWFFuncIterator method iterate.

public List<DLA3DWFFuncPoint> iterate() {
    List<DLA3DWFFuncPoint> res = new ArrayList<>();
    DLA3DWFFuncPoint initialPoint = new DLA3DWFFuncPoint();
    res.add(initialPoint);
    innerRadius = 3.0;
    outerRadius = 3.0 * innerRadius;
    while (res.size() < max_iter) {
        double phi = randGen.random() * (M_PI + M_PI);
        sinAndCos(phi, sinPhi, cosPhi);
        double theta = randGen.random() * (M_PI + M_PI);
        sinAndCos(theta, sinTheta, cosTheta);
        double ci = innerRadius * sinTheta.value * cosPhi.value;
        double cj = innerRadius * sinTheta.value * sinPhi.value;
        double ck = innerRadius * cosTheta.value;
        if (thread_count > 1) {
            List<WalkerThread> threads = new ArrayList<>();
            for (int i = 0; i < 2 * thread_count; i++) {
                WalkerThread thread = new WalkerThread(ci, cj, ck, res);
                threads.add(thread);
                new Thread(thread).start();
            }
            boolean isDone = false;
            while (!isDone) {
                isDone = true;
                for (WalkerThread thread : threads) {
                    if (!thread.isDone()) {
                        isDone = false;
                        try {
                            Thread.sleep(1);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                }
            }
            for (WalkerThread thread : threads) {
                DLA3DWFFuncPoint nextPoint = thread.getRes();
                if (nextPoint != null) {
                    res.add(nextPoint);
                    if (res.size() > 1000 && res.size() % 100 == 0) {
                        System.out.println("PNTS " + res.size());
                    }
                }
            }
        } else {
            DLA3DWFFuncPoint nextPoint = nextWalk(ci, cj, ck, res);
            if (nextPoint != null) {
                res.add(nextPoint);
                if (res.size() > 1000 && res.size() % 100 == 0) {
                    System.out.println("PNTS " + res.size());
                }
            }
        }
    }
    for (DLA3DWFFuncPoint p : res) {
        p.relDepth = (double) p.pathLength / (double) calcMaxPathLength(res, p);
        if (p.parent != null) {
            VectorD d = new VectorD(p.x - p.parent.x, p.y - p.parent.y, p.z - p.parent.z);
            d.normalize();
            p.elevation = MathLib.atan2(d.y, d.x) + MathLib.M_PI_2;
            p.azimuth = -MathLib.atan2(d.z, MathLib.sqrt(d.x * d.x + d.y * d.y));
            double sina = MathLib.sin(p.elevation);
            double cosa = MathLib.cos(p.elevation);
            double sinb = MathLib.sin(p.azimuth);
            double cosb = MathLib.cos(p.azimuth);
            Matrix3D a = new Matrix3D();
            a.m[0][0] = cosb;
            a.m[0][1] = 0;
            a.m[0][2] = sinb;
            a.m[1][0] = sina * sinb;
            a.m[1][1] = cosa;
            a.m[1][2] = -sina * cosb;
            a.m[2][0] = -cosa * sinb;
            a.m[2][1] = sina;
            a.m[2][2] = cosa * cosb;
            p.rotation = a;
        }
    }
    return res;
}
Also used : Matrix3D(org.jwildfire.base.mathlib.VecMathLib.Matrix3D) ArrayList(java.util.ArrayList) VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD)

Aggregations

ArrayList (java.util.ArrayList)1 Matrix3D (org.jwildfire.base.mathlib.VecMathLib.Matrix3D)1 VectorD (org.jwildfire.base.mathlib.VecMathLib.VectorD)1