public static Plane3d[] createPlanes(List<CrossSectionElement> crossSection) { Plane3d[] seg = new Plane3d[crossSection.size() - 1]; for (int i = 1; i < crossSection.size(); i++) { CrossSectionElement first = crossSection.get(i - 1); CrossSectionElement second = crossSection.get(i); Point3d p = new Point3d(0, first.p.y, -first.p.x); Vector3d v = new Vector3d(0, second.p.x - first.p.x, second.p.y - first.p.y); v.normalize(); Plane3d plane3d = new Plane3d(p, v); seg[i - 1] = plane3d; } return seg; }
/** * Calculates height of point where it intersect with the plane. * * @param point * the 2d point * @param plane * the surface plane * @return the height of point where it intersect with the plane */ private double calcHeight(Point2d point, Plane3d plane) { double x = point.x; double z = -point.y; return plane.calcYOfPlane(x, z); }
/** * Build roof hook space for rectangle edge. * * @param pEdge * rectangle edge number XXX * @param pRectangleContur * rectangle XXX * @param pPolygonPlane * polygon and plane defining height connected with rectangle * edge * @return roof hook space */ public static PolygonRoofHooksSpace buildRecHookSpace(Point2d p1, Vector2d v1, PolygonPlane pPolygonPlane) { if (pPolygonPlane == null) { return null; } Plane3d plane = new Plane3d(pPolygonPlane.getPlane().getPoint(), pPolygonPlane.getPlane().getNormal()); return new PolygonRoofHooksSpace(p1, v1, pPolygonPlane.getPolygon(), plane); }
/** * @param pMeshRoof * @param pPlane * @param pTextureVector * @param pTextureData * @param textureOffsetU * @param textureOffsetV * @param normalIndex * @param face * @param point2d */ private static void addPointToTriangleFace(MeshFactory pMeshRoof, Plane3d pPlane, Vector3d pTextureVector, TextureData pTextureData, double textureOffsetU, double textureOffsetV, int normalIndex, FaceFactory face, Point2d point2d) { double h = pPlane.calcYOfPlane(point2d.x, -point2d.y); Point3d point3d = new Point3d(point2d.x, h, -point2d.y); int vi = pMeshRoof.addVertex(point3d); // Point3d point3d = pMeshRoof.vertices.get(vi); face.addVertIndex(vi); face.addNormalIndex(normalIndex); TextCoord calcUV = TextCordFactory.calcFlatSurfaceUV(point3d, pPlane.getNormal(), pTextureVector, pPlane.getPoint(), pTextureData, textureOffsetU, textureOffsetV); int tci = pMeshRoof.addTextCoord(calcUV); face.addCoordIndex(tci); }
final Plane3d planeTop = new Plane3d(planePoint, normalTop); final Plane3d planeBottom = new Plane3d(planePoint, normalBottom); double leftTopY = -planeTop.calcZOfPlane(0, h2); double leftBottomY = -planeBottom.calcZOfPlane(0, h2); final LinePoints2d rightTopLine = new LinePoints2d(rightCenter, rightTop); double leftHeight = planeBottom.calcYOfPlane(leftBottom.x, -leftBottom.y); if (l1 < 0.5 * recHeight) { leftHeight = planeTop.calcYOfPlane(leftTop.x, -leftTop.y); double rightHeight = planeBottom.calcYOfPlane(rightBottom.x, -rightBottom.y); if (l1 < 0.5 * recHeight) { rightHeight = planeTop.calcYOfPlane(rightTop.x, -rightTop.y); final Plane3d planeLeft = new Plane3d(new Point3d(leftCenter.x, h1, -leftCenter.y), new Vector3d( -(h1 - leftHeight), l2, 0)); final Plane3d planeRight = new Plane3d(new Point3d(rightCenter.x, h1, -rightCenter.y), new Vector3d( -(rightHeight - h1), l2, 0));
Vector3d pTextureVector, TextureData pTextureData, double textureOffsetU, double textureOffsetV) { int normalIndex = pMeshRoof.addNormal(pPlane.getNormal());
int normalIndex = pMeshRoof.addNormal(plane2.getNormal()); double h = plane2.calcYOfPlane(point2d.x, -point2d.y); TextCoord calcUV = TextCordFactory.calcFlatSurfaceUV(point3d, plane2.getNormal(), pRoofLineVector, plane2.getPoint(), roofTexture, textureOffsetU, textureOffsetV);
/** * Creates planes for each edge in polygon. * * @param polygon * the polygon * @param height * the height of roof * @param m * the middle point * @return the planes for each polygon edge */ public static Plane3d[] createPlanes(List<Point2d> polygon, double height, Point2d m) { int size = polygon.size(); Plane3d[] ret = new Plane3d[size]; // Point3d center = new Point3d(m.x, height, -m.y); for (int i = 0; i < size; i++) { Point2d p1 = polygon.get(i); Point2d p2 = polygon.get((i + 1) % size); Vector3d v1 = new Vector3d(p1.x - m.x, -height, -(p1.y - m.y)); Vector3d v2 = new Vector3d(p2.x - m.x, -height, -(p2.y - m.y)); v1.cross(v1, v2); v1.normalize(); Point3d point = new Point3d(p1.x, 0, -p1.y); // Point3d point = new Point3d(p2.x, 0, -p2.y); Plane3d p = new Plane3d(point, v1); ret[i] = p; } return ret; }
Point3d planePoint= TransformationMatrix3d.transform(pPlane.getPoint(), tr3d); Vector3d planeNormal = TransformationMatrix3d.transform(pPlane.getNormal(), tr3d); this.plane = new Plane3d(planePoint, planeNormal); SimpleMatrix trBack = TransformationMatrix3d.tranA(p1.x, 0, -p1.y).mult(TransformationMatrix3d.rotYA(angle));
/** * Calculate height of point in border. * * @param point * @param mLine * @param planeTop * @param planeBottom * @return */ private double calcHeight(Point2d point, Plane3d plane) { double x = point.x; double z = -point.y; return plane.calcYOfPlane(x, z); }
public static void buildFlatRoof(PolygonList2d borderPolygon, MeshFactory meshRoof, TextureData roofTexture) { MultiPolygonList2d topMP = new MultiPolygonList2d(borderPolygon); // build flat Point3d planeRightTopPoint = new Point3d(0, 0, 0); Vector3d nt = new Vector3d(0, 1, 0); Plane3d planeTop = new Plane3d(planeRightTopPoint, nt); Vector3d roofTopLineVector = new Vector3d(-1d, 0, 0); MeshFactoryUtil.addPolygonToRoofMesh(meshRoof, topMP, planeTop, roofTopLineVector, roofTexture); }
public RectangleRoofHooksSpace(Point2d p1, Vector2d v1, double b, Plane3d pPlane) { super(); // this.p1 = p1; // this.v1 = v1; this.b = b; double angle = Math.atan2(v1.y, v1.x); // Math.toDegrees(angle); SimpleMatrix tr2d = TransformationMatrix2d.rotZA(-angle).mult(TransformationMatrix2d.tranA(-p1.x, -p1.y)); SimpleMatrix tr3d = TransformationMatrix3d.rotYA(-angle).mult(TransformationMatrix3d.tranA(-p1.x, 0, p1.y)); this.p1 = TransformationMatrix2d.transform(p1, tr2d); this.v1 = TransformationMatrix2d.transform(v1, tr2d); Point3d planePoint= TransformationMatrix3d.transform(pPlane.getPoint(), tr3d); Vector3d planeNormal = TransformationMatrix3d.transform(pPlane.getNormal(), tr3d); this.plane = new Plane3d(planePoint, planeNormal); SimpleMatrix trBack = TransformationMatrix3d.rotYA(angle).mult(TransformationMatrix3d.tranA(-p1.x, 0, p1.y)); this.transformationMatrix = trBack; }
/** * Calculates height of point in wall. * * @param point * the point * @param planeTop * the top plane * @return the height of point */ private static double calcHeight(Point2d point, Plane3d planeTop) { double x = point.x; double z = -point.y; return planeTop.calcYOfPlane(x, z); } }
private static void addPolygonWithHolesInY(PolygonWithHolesList2d polygonWithHolesList2d, double height, MeshFactory meshFactory, TextureData textureData, double textureStartPointX, double textureStartPointY, Vector3d textureDirection, boolean top) { List<Triangle2d> topMP = Poly2TriSimpleUtil.triangulate(polygonWithHolesList2d); Vector3d yt = new Vector3d(0, 1, 0); if (!top) { yt.negate(); } Point3d textureStartPoint = new Point3d(textureStartPointX, height, -textureStartPointY); Plane3d planeTop = new Plane3d(textureStartPoint, yt); addPolygonToRoofMesh(meshFactory, topMP, planeTop, textureDirection, textureData, 0, 0); }
/** * Calculates height of point in wall. * * @param point * @param rLine * @param lLine * @param planeLeft * @param planeRight * @param planeButtom * @param planeTop * @return */ private static double calcHeight(Point2d point, LinePoints2d lLine, Plane3d planeButtom, Plane3d planeTop) { double x = point.x; double z = -point.y; if (lLine.inFront(point)) { return planeButtom.calcYOfPlane(x, z); } else { return planeTop.calcYOfPlane(x, z); } }
private Plane3d createEdgePlane(LineSegment2d edge, double heightFactor) { Vector3d faceNormal = calcFaceNormal(edge, heightFactor); return new Plane3d(new Point3d(edge.getBegin().x, 0, -edge.getBegin().y), faceNormal); }
/** * Calculate height of point in wall. * * @param point * the point * @param mLine * the middle line * @param planeTop * the top plane * @param planeBottom * the bottom plane * @return */ private static double calcHeight(Point2d point, LinePoints2d mLine, Plane3d planeTop, Plane3d planeBottom) { double x = point.x; double z = -point.y; if (mLine.inFront(point)) { return planeTop.calcYOfPlane(x, z); } else { return planeBottom.calcYOfPlane(x, z); } } }
/** * Creates roof plane. * * @param h1 * height 1 * @param h2 * height 2 * @param h3 * height 3 * @param recHeight * @param recWidth * @return roof plane */ private Plane3d createRoofPlane(double h1, double h2, double h3, double recWidth, double recHeight) { Point3d p1 = new Point3d(0, h1, 0); Vector3d v2 = new Vector3d(0, h2, -recHeight); v2.sub(p1); Vector3d v3 = new Vector3d(recWidth, h3, 0); v3.sub(p1); Vector3d normal = new Vector3d(); normal.cross(v3, v2); return new Plane3d(p1, normal); }
/** * Calculates height of wall point under roof. * * @param point * the point * @param rLine * the right split line * @param lLine * the left split line * @param planeLeft * the left plane * @param planeRight * the right plane * @param planeButtom * the bottom plane * @return height of point */ private static double calcHeight(Point2d point, LinePoints2d rLine, LinePoints2d lLine, Plane3d planeLeft, Plane3d planeRight, Plane3d planeButtom) { double x = point.x; double z = -point.y; if (rLine.inFront(point)) { return planeRight.calcYOfPlane(x, z); } else if (lLine.inFront(point)) { return planeLeft.calcYOfPlane(x, z); } else { return planeButtom.calcYOfPlane(x, z); } }