use of com.ardor3d.math.type.ReadOnlyVector2 in project energy3d by concord-consortium.
the class Foundation method ensureIncludesChildren.
private void ensureIncludesChildren(final Vector3 p, final int index) {
if (children.isEmpty()) {
return;
}
useOrgPoints = true;
final List<Vector2> insidePoints = new ArrayList<Vector2>(children.size() * 2);
for (final HousePart part : children) {
if (part.children.size() > 2 && part.getPoints().size() > 1) {
final Vector3 p0 = part.getAbsPoint(0);
final Vector3 p2 = part.getAbsPoint(2);
insidePoints.add(new Vector2(p0.getX(), p0.getY()));
insidePoints.add(new Vector2(p2.getX(), p2.getY()));
} else {
// if the child is a solar panel, a rack, or a mirror
final Vector3 p0 = part.getAbsPoint(0);
insidePoints.add(new Vector2(p0.getX(), p0.getY()));
}
}
final Vector3 p0 = getAbsPoint(0);
final Vector3 p1 = getAbsPoint(1);
final Vector3 p2 = getAbsPoint(2);
final ReadOnlyVector2 p0_2d = new Vector2(p0.getX(), p0.getY());
final ReadOnlyVector2 p1_2d = new Vector2(p1.getX(), p1.getY());
final ReadOnlyVector2 p2_2d = new Vector2(p2.getX(), p2.getY());
useOrgPoints = false;
double uScaleMin = Double.MAX_VALUE;
double uScaleMax = -Double.MAX_VALUE;
double vScaleMin = Double.MAX_VALUE;
double vScaleMax = -Double.MAX_VALUE;
for (final Vector2 insidePoint : insidePoints) {
final double uScale = Util.projectPointOnLineScale(insidePoint, p0_2d, p2_2d);
if (uScaleMin > uScale) {
uScaleMin = uScale;
}
if (uScaleMax < uScale) {
uScaleMax = uScale;
}
final double vScale = Util.projectPointOnLineScale(insidePoint, p0_2d, p1_2d);
if (vScaleMin > vScale) {
vScaleMin = vScale;
}
if (vScaleMax < vScale) {
vScaleMax = vScale;
}
}
final double uScaleP = Util.projectPointOnLineScale(new Vector2(p.getX(), p.getY()), p0_2d, p2_2d);
final double vScaleP = Util.projectPointOnLineScale(new Vector2(p.getX(), p.getY()), p0_2d, p1_2d);
final double uScaleP0 = Util.projectPointOnLineScale(new Vector2(points.get(0).getX(), points.get(0).getY()), p0_2d, p2_2d);
final double uScaleP2 = Util.projectPointOnLineScale(new Vector2(points.get(2).getX(), points.get(2).getY()), p0_2d, p2_2d);
final double vScaleP0 = Util.projectPointOnLineScale(new Vector2(points.get(0).getX(), points.get(0).getY()), p0_2d, p1_2d);
final double vScaleP1 = Util.projectPointOnLineScale(new Vector2(points.get(1).getX(), points.get(1).getY()), p0_2d, p1_2d);
final boolean isOnRight = uScaleP2 >= uScaleP0 && (index == 2 || index == 3);
final boolean isOnTop = vScaleP1 >= vScaleP0 && (index == 1 || index == 3);
final double uScale;
if (isOnRight && uScaleP < uScaleMax) {
uScale = uScaleMax;
} else if (!isOnRight && uScaleP > uScaleMin) {
uScale = uScaleMin;
} else {
uScale = uScaleP;
}
final double vScale;
if (isOnTop && vScaleP < vScaleMax) {
vScale = vScaleMax;
} else if (!isOnTop && vScaleP > vScaleMin) {
vScale = vScaleMin;
} else {
vScale = vScaleP;
}
final Vector3 u = p2.subtract(p0, null);
final Vector3 v = p1.subtract(p0, null);
p.set(p0).addLocal(u.multiplyLocal(uScale)).addLocal(v.multiplyLocal(vScale));
}
use of com.ardor3d.math.type.ReadOnlyVector2 in project energy3d by concord-consortium.
the class Roof method snapToWallsPolygon.
protected void snapToWallsPolygon(final Vector3 p) {
if (!insideWallsPolygon(p)) {
final ReadOnlyVector2 p2D = Util.snapToPolygon(p, wallUpperPoints, wallNormals);
p.set(p2D.getX(), p2D.getY(), p.getZ());
}
}
Aggregations