private Point2d transformToLocal(Point2d point) { return TransformationMatrix2d.transform(point, transformationToLocal); } }
private Vector2d getBisector(Point2d p1, Point2d p2) { return Vector2dUtil.orthogonalRight(Vector2dUtil.fromTo(p1, p2)); }
/** * @param x * @param y * @param alpha * @param sizeA * @param sizeB * @return */ public static SimpleMatrix trandformToLocalMatrix2d(double x, double y, double alpha) { SimpleMatrix transfLocal = TransformationMatrix2d.tranA(-x, -y); SimpleMatrix rotLocal = TransformationMatrix2d.rotZA(-alpha); // XXX test me return rotLocal.mult(transfLocal); }
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; }
private static Point3d[][] buildMesh(Point2d center, Point2d[] crossSection, int sectionCount) { int crossCount = crossSection.length; Point3d[][] mesh = new Point3d[sectionCount][]; for (int i = 0; i < sectionCount; i++) { double a = Math.toRadians(360) / sectionCount * i; SimpleMatrix tranA = TransformationMatrix3d.tranA(center.x, 0, -center.y); SimpleMatrix rotY = TransformationMatrix3d.rotYA(a); SimpleMatrix trans = tranA.mult(rotY); Point3d[] crossMesh = new Point3d[crossCount]; for (int j = 0; j < crossSection.length; j++) { // point Point2d cross = crossSection[j]; Point3d p = new Point3d(cross.x, cross.y, 0); crossMesh[j] = TransformationMatrix3d.transform(p, trans); } mesh[i] = crossMesh; } return mesh; }
private static Vector2d[] calsSoftNormals(Point2d[] crossSection) { Vector2d[] ret = new Vector2d[crossSection.length]; Vector2d[] normals = new Vector2d[crossSection.length - 1]; for (int i = 0; i < crossSection.length - 1; i++) { Vector2d n = new Vector2d(crossSection[i + 1]); n.sub(crossSection[i]); n.normalize(); normals[i] = n; } for (int i = 1; i < crossSection.length - 1; i++) { Vector2d n1 = normals[i - 1]; Vector2d n2 = normals[i]; Vector2d n = Vector2dUtil.bisectorNormalized(n1, n2); n.normalize(); ret[i] = n; } ret[0] = Vector2dUtil.orthogonalLeft(normals[0]); ret[crossSection.length - 1] = Vector2dUtil.orthogonalLeft(normals[normals.length - 1]); for (Vector2d element : ret) { element.negate(); } return ret; }
private Vector3d calcFaceNormal(LineSegment2d edge, double heightFactor) { Vector2d edgeVector = Vector2dUtil.fromTo(edge.getBegin(), edge.getEnd()); edgeVector.normalize(); Vector2d edgeOrthogonal = Vector2dUtil.orthogonalLeft(edgeVector); Vector3d v1 = new Vector3d(edgeVector.x, 0, -edgeVector.y); Vector3d v2 = new Vector3d(edgeOrthogonal.x, heightFactor, -edgeOrthogonal.y); v1.cross(v1, v2); v1.normalize(); return v1; }
/** * Sets camera position and rotation. * * @param pGlu * GLU */ private void setCamera(GLU pGlu) { Point3d pos = this.simpleMoveAnimator.getPoint(); Vector3d posLookAt = new Vector3d(100, 0, 0); Vector3d rotate = this.simpleMoveAnimator.getAngle(); posLookAt = PointUtil.rotateZ3d(posLookAt, rotate.z); posLookAt = PointUtil.rotateY3d(posLookAt, rotate.y); posLookAt.add(pos); pGlu.gluLookAt(pos.x, pos.y, pos.z, posLookAt.x, posLookAt.y, posLookAt.z, 0, 1, 0); }
@Override public Object evalZeroParam(Context context) { Vector2d bisector = Context.getRequiredContextVariable("bisector", context, Vector2d.class); return Math.toDegrees(AngleUtil.angle(Vector2dUtil.orthogonalLeft(bisector))); }
@Override public RoofTypeOutput buildRoof(Point2d pStartPoint, PolygonWithHolesList2d buildingPolygon, DormerRoofModel pRoof, double height, RoofMaterials roofTextureData) { SimpleMatrix transformLocal = TransformationMatrix2d.tranA(-pStartPoint.x, -pStartPoint.y); List<Point2d> polygon = buildingPolygon.getOuter().getPoints(); polygon = TransformationMatrix2d.transformList(polygon, transformLocal); Double h1 = null; Double angle = null; Measurement measurement = pRoof.getMeasurements().get(MeasurementKey.HEIGHT_1); if (isUnit(measurement, MeasurementUnit.DEGREES)) { angle = measurement.getValue(); } else { h1 = getHeightMeters(pRoof.getMeasurements(), MeasurementKey.HEIGHT_1, DEFAULT_ROOF_HEIGHT); } RoofTypeOutput rto = build(polygon, h1, angle, roofTextureData); SimpleMatrix transformGlobal = TransformationMatrix3d.tranA(pStartPoint.x, height - rto.getHeight(), -pStartPoint.y); rto.setTransformationMatrix(transformGlobal); return rto; }
/** * Prepare transformation matrix from local rectangle roof coordinates to * global building coordinates. * * @param startPoint * rectangle roof starting point * @param height * roof minimal height * @param alpha * roof angle * @return */ public static SimpleMatrix prepareTransformToGlobalMatrix3d(Point2d startPoint, double height, double alpha) { SimpleMatrix transf = TransformationMatrix3d.tranA(startPoint.x, height, -startPoint.y); SimpleMatrix rot = TransformationMatrix3d.rotYA(alpha); // XXX test me return transf.mult(rot); }
public static int[][] buildNormalsIndexs(MeshFactory meshFactory, Point3d[][] mesh, Point3d center3d, int pointCount, int crossCount) { int[][] softNormalsIndexs = new int[pointCount][]; for (int i = 0; i < pointCount; i++) { softNormalsIndexs[i] = new int[crossCount]; for (int j = 0; j < crossCount; j++) { Point3d p = mesh[i][j]; Vector3d n = Vector3dUtil.fromTo(center3d, p); n.normalize(); int in = meshFactory.addNormal(n); softNormalsIndexs[i][j] = in; } } return softNormalsIndexs; }
@Override public RoofTypeOutput buildRoof(Point2d startPoint, PolygonWithHolesList2d buildingPolygon, DormerRoofModel roof, double height, RoofMaterials roofTextureData) { SimpleMatrix transformLocal = TransformationMatrix2d.tranA(-startPoint.x, -startPoint.y); PolygonWithHolesList2d buildingTransformed = PolygonWithHolesList2dUtil.transform(buildingPolygon, transformLocal); Measurement measurement = roof.getMeasurements().get(MeasurementKey.HEIGHT_1); Double h1 = null; Double angle = null; if (isUnit(measurement, MeasurementUnit.DEGREES)) { angle = measurement.getValue(); } else { h1 = getHeightMeters(roof.getMeasurements(), MeasurementKey.HEIGHT_1, 2.5d); } RoofTypeOutput rto = build(buildingTransformed, h1, angle, 0, 0, roofTextureData); SimpleMatrix transformGlobal = TransformationMatrix3d.tranA(startPoint.x, height - rto.getHeight(), -startPoint.y); rto.setTransformationMatrix(transformGlobal); return rto; }
private Vector2d getBisector(Point2d p1, Point2d p2, Point2d p3) { Vector2d v = Vector2dUtil.bisector(p1, p2, p3); v.negate(); return v; }
private static PolygonList2d transformPolygon(PolygonList2d polygon, SimpleMatrix transformLocal) { return new PolygonList2d(TransformationMatrix2d.transformList(polygon.getPoints(), transformLocal)); }
private static double calcDistance(Point2d pIntersect, LineSegment2d edgeLine) { Vector2d edge = new Vector2d(edgeLine.getEnd()); edge.sub(edgeLine.getBegin()); Point2d intersect = new Point2d(pIntersect); intersect.sub(edgeLine.getBegin()); Vector2d pointOnVector = Algebra.orthogonalProjection(edge, intersect); return Tuple2dUtil.distance(intersect, pointOnVector); }
@Override public Double eval(Context context) { Double argument = getOptionalArgument(0, Double.class); if (argument == null) { argument = 0d; } Vector2d bisector = getRequiredContextVariable("bisector", context, Vector2d.class); return Math.toDegrees(AngleUtil.angle(Vector2dUtil.orthogonalLeft(bisector))) + argument; }
@Override public RoofTypeOutput buildRoof(Point2d pStartPoint, PolygonWithHolesList2d buildingPolygon, DormerRoofModel pRoof, double height, RoofMaterials roofTextureData) { List<Point2d> pPolygon = buildingPolygon.getOuter().getPoints(); SimpleMatrix transformLocal = TransformationMatrix2d.tranA(-pStartPoint.x, -pStartPoint.y); pPolygon = TransformationMatrix2d.transformList(pPolygon, transformLocal); // rectangleContur = // TransformationMatrix2d.transformArray(rectangleContur, // transformLocal); PolygonList2d borderPolygon = new PolygonList2d(pPolygon); Circle circle = CircleInsidePolygon.iterativeNonConvex(borderPolygon, 0.01); int isection = getIsection(pRoof.getRoofTypeParameter()); boolean soft = isSoft(pRoof.getRoofTypeParameter()); Bend[] bends = getBends(pRoof.getMeasurements(), circle); RoofTypeOutput rto = build(pPolygon, circle.getPoint(), bends, isection, soft, roofTextureData); SimpleMatrix transformGlobal = TransformationMatrix3d.tranA(pStartPoint.x, height - rto.getHeight(), -pStartPoint.y); rto.setTransformationMatrix(transformGlobal); return rto; }
/** * Prepare transformation matrix from local rectangle roof coordinates to * global building coordinates. * * @param startPoint * rectangle roof starting point * * @param alpha * roof angle * @return */ public static SimpleMatrix prepareTransformMatrixToGlobal2d(Point2d startPoint, double alpha) { SimpleMatrix transf = TransformationMatrix2d.tranA(startPoint.x, startPoint.y); SimpleMatrix rot = TransformationMatrix2d.rotZA(alpha); // XXX test me return transf.mult(rot); }
private SegmentHeight transformToGlobal(SegmentHeight segmentHeight) { Point2d begin = segmentHeight.getBegin(); Point2d end = segmentHeight.getEnd(); double beginHeight = segmentHeight.getBeginHeight(); double endHeight = segmentHeight.getEndHeight(); /* Do transformation to global frame. */ return new SegmentHeight( // TransformationMatrix2d.transform(begin, transformationToGlobal),// beginHeight + transformToGlobalHeightOffset, // TransformationMatrix2d.transform(end, transformationToGlobal),// endHeight + transformToGlobalHeightOffset); }