Search in sources :

Example 11 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class Polygon method getAABB.

/**
 * @return Vrati AABB pre Polygon sluziaci na rozsah generovanych ohnisk pre
 * fraktury. Preto je to umelo nafunknute o konstantu 1.
 */
public AABB getAABB() {
    if (count == 0) {
        return null;
    } else {
        float minX = Float.POSITIVE_INFINITY;
        float minY = Float.POSITIVE_INFINITY;
        float maxX = Float.NEGATIVE_INFINITY;
        float maxY = Float.NEGATIVE_INFINITY;
        for (int i = 0; i < count; ++i) {
            Tuple2f v = get(i);
            minX = Math.min(v.x, minX);
            maxX = Math.max(v.x, maxX);
            minY = Math.min(v.y, minY);
            maxY = Math.max(v.y, maxY);
        }
        return new AABB(new v2(minX - AABBConst, minY - AABBConst), new v2(maxX + AABBConst, maxY + AABBConst), false);
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) spacegraph.util.math.v2(spacegraph.util.math.v2) AABB(spacegraph.space2d.phys.collision.AABB)

Example 12 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class Polygon method mass.

/**
 * @return Vrati hmotnost telesa.
 */
public double mass() {
    double m = 0;
    for (int i = 0, j = 1; i != count; i = j, j++) {
        Tuple2f b1 = get(i);
        Tuple2f b2 = get(j == count ? 0 : j);
        m += Tuple2f.cross(b1, b2);
    }
    m = Math.abs(m / 2);
    return m;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Example 13 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class Polygon method inside.

/**
 * Existuje efektivnejsia implementacia v pripade, ze bodov je viacej.
 * http://alienryderflex.com/polygon/
 * Este upravena by bola vziat vsetky hrany
 *
 * @param p
 * @return Vrati true.
 */
public boolean inside(Tuple2f p) {
    int i, j;
    boolean c = false;
    Tuple2f v = new v2();
    for (i = 0, j = count - 1; i < count; j = i++) {
        Tuple2f a = get(i);
        Tuple2f b = get(j);
        v.set(b);
        v.subbed(a);
        if (((a.y >= p.y) != (b.y >= p.y)) && (p.x <= v.x * (p.y - a.y) / v.y + a.x)) {
            c = !c;
        }
    }
    return c;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) spacegraph.util.math.v2(spacegraph.util.math.v2)

Example 14 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class AEdge method kolmicovyBod.

/**
 * @param point
 * @return Vrati najvlizsi bod na priamke voci bodu z parametra.
 */
public Tuple2f kolmicovyBod(Tuple2f point) {
    Tuple2f U = p2.sub(p1);
    Tuple2f V = new v2(p1.y - p2.y, p2.x - p1.x);
    float uv = cross(U, V);
    if (uv == 0) {
        // su to rovnobezky (ak su v jednej polohe, system to neosetruje)
        return null;
    }
    float k = (cross(point, V) - cross(p1, V)) / uv;
    if (k >= 0 && k <= 1) {
        U.scaled(k);
        return p1.add(U);
    } else {
        double dist1 = (double) p1.distanceSq(point);
        double dist2 = (double) p2.distanceSq(point);
        return dist1 < dist2 ? p1 : p2;
    }
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) spacegraph.util.math.v2(spacegraph.util.math.v2)

Example 15 with Tuple2f

use of spacegraph.util.math.Tuple2f in project narchy by automenta.

the class Smasher method pointInPolygon.

/**
 * @param v
 * @return Vrati true, pokial sa vrchol nachadza v polygone. Treba mat
 * predpocitane hodnoty primarneho polygonu metodou precalc_values().
 */
private boolean pointInPolygon(Tuple2f v) {
    float x = v.x;
    float y = v.y;
    int n = p.size();
    int i, j = n - 1;
    boolean b = false;
    for (i = 0; i < n; i++) {
        Tuple2f vi = p.get(i);
        Tuple2f vj = p.get(j);
        if ((vi.y < y && vj.y >= y || vj.y < y && vi.y >= y) && y * multiple[i] + constant[i] < x) {
            b = !b;
        }
        j = i;
    }
    return b;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f)

Aggregations

Tuple2f (spacegraph.util.math.Tuple2f)154 spacegraph.util.math.v2 (spacegraph.util.math.v2)32 Rot (spacegraph.space2d.phys.common.Rot)23 AABB (spacegraph.space2d.phys.collision.AABB)7 Vec2 (spacegraph.space2d.phys.common.Vec2)6 Body2D (spacegraph.space2d.phys.dynamics.Body2D)6 ManifoldPoint (spacegraph.space2d.phys.collision.ManifoldPoint)5 VelocityConstraintPoint (spacegraph.space2d.phys.dynamics.contacts.ContactVelocityConstraint.VelocityConstraintPoint)5 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)4 Joint (spacegraph.space2d.phys.dynamics.joints.Joint)4 PolygonFixture (spacegraph.space2d.phys.fracture.PolygonFixture)4 MyList (spacegraph.space2d.phys.fracture.util.MyList)4 FasterList (jcog.list.FasterList)3 CircleShape (spacegraph.space2d.phys.collision.shapes.CircleShape)3 Shape (spacegraph.space2d.phys.collision.shapes.Shape)3 Transform (spacegraph.space2d.phys.common.Transform)3 DistanceJoint (spacegraph.space2d.phys.dynamics.joints.DistanceJoint)3 MouseJoint (spacegraph.space2d.phys.dynamics.joints.MouseJoint)3 Fragment (spacegraph.space2d.phys.fracture.Fragment)3 Polygon (spacegraph.space2d.phys.fracture.Polygon)3