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);
}
}
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;
}
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;
}
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;
}
}
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;
}
Aggregations