/** * Creates a calculator for the camera translation. * @param up indicates which way is up. */ public CameraTranslationCalculator(Vector3d up) { down.negate(up); }
/** * Returns the default reference vector for the alignment of Cn structures * @return */ private Vector3d getReferenceAxisCylic() { // get principal axis vector that is perpendicular to the principal // rotation vector Vector3d vmin = null; double dotMin = 1.0; for (Vector3d v: principalAxesOfInertia) { if (Math.abs(principalRotationVector.dot(v)) < dotMin) { dotMin = Math.abs(principalRotationVector.dot(v)); vmin = new Vector3d(v); } } if (principalRotationVector.dot(vmin) < 0) { vmin.negate(); } return vmin; }
private Vector3d orthogonalize(Vector3d vector1, Vector3d vector2) { double dot = vector1.dot(vector2); Vector3d ref = new Vector3d(vector2); // System.out.println("p.r: " + dot); // System.out.println("Orig refVector: " + referenceVector); if (dot < 0) { vector2.negate(); } if (Math.abs(dot) < 0.00001) { logger.info("HelixAxisAligner: reference axis parallel"); } vector2.cross(vector1, vector2); // System.out.println("Intermed. refVector: " + vector2); vector2.normalize(); // referenceVector.cross(referenceVector, principalRotationVector); vector2.cross(vector1, vector2); vector2.normalize(); if (ref.dot(vector2) < 0) { vector2.negate(); } // System.out.println("Mod. refVector: " + vector2); return vector2; } /**
private Vector3d orthogonalize(Vector3d vector1, Vector3d vector2) { double dot = vector1.dot(vector2); Vector3d ref = new Vector3d(vector2); // System.out.println("p.r: " + dot); // System.out.println("Orig refVector: " + referenceVector); if (dot < 0) { vector2.negate(); } vector2.cross(vector1, vector2); // System.out.println("Intermed. refVector: " + vector2); vector2.normalize(); // referenceVector.cross(referenceVector, principalRotationVector); vector2.cross(vector1, vector2); vector2.normalize(); if (ref.dot(vector2) < 0) { vector2.negate(); } // System.out.println("Mod. refVector: " + vector2); return vector2; } /**
private void initialize() { // translation to centered coordinate system centroid = new Vector3d(subunits.getCentroid()); // translation back to original coordinate system Vector3d reverse = new Vector3d(centroid); reverse.negate(); centroidInverse.set(reverse); // // On LINUX there seems to be a bug with vecmath, and element m33 is zero. Here we make sure it's 1. centroidInverse.setElement(3, 3, 1.0); }
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); }
/** * Returns the default reference vector for the alignment of Cn structures * @return */ private Vector3d getReferenceAxisCylic() { if (rotationGroup.getPointGroup().equals("C2")) { Vector3d vr = new Vector3d(subunits.getOriginalCenters().get(0)); vr.sub(subunits.getCentroid()); vr.normalize(); return vr; } // get principal axis vector that is perpendicular to the principal // rotation vector Vector3d vmin = null; double dotMin = 1.0; for (Vector3d v: principalAxesOfInertia) { if (Math.abs(principalRotationVector.dot(v)) < dotMin) { dotMin = Math.abs(principalRotationVector.dot(v)); vmin = new Vector3d(v); } } if (principalRotationVector.dot(vmin) < 0) { vmin.negate(); } return vmin; }
/** * Creates a calculator for the camera rotation. * @param up indicates which way is up. * @param forward indicates which is forward. * @throws RuntimeException if {@code up} and {@code forward} are not orthogonal. */ public CameraRotationCalculator(Vector3d up, Vector3d forward) { Vector3d left = new Vector3d(); left.cross(up, forward); if (!MathTools.epsilonEquals(left.length(), 1.0, 1.0 - 5)) throw new RuntimeException("The vectors up and forward must be orthogonal. Received: up = " + up + ", forward = " + forward); this.up.set(up); this.forward.set(forward); down.negate(up); computeOffset(); }
public void setFinalApproach(FrameVector finalDirection, double approachDistance) { this.finalDirection.set(finalDirection); this.finalDirection.normalize(); this.finalDirection.get(tempVector); tempVector.negate(); GeometryTools.getAxisAngleFromZUpToVector(tempVector, axisAngleToWorld); rotationPlane.setIncludingFrame(this.finalDirection.getReferenceFrame(), axisAngleToWorld); this.approachDistance.set(approachDistance); }
private void initialize() { // translation to centered coordinate system centroid = new Vector3d(subunits.getCentroid()); // translation back to original coordinate system Vector3d reverse = new Vector3d(centroid); reverse.negate(); centroidInverse.set(reverse); // Make sure matrix element m33 is 1.0. An old version vecmath did not set this element. centroidInverse.setElement(3, 3, 1.0); List<Point3d> centers = subunits.getCenters(); int n = subunits.getSubunitCount(); originalCoords = new Point3d[n]; transformedCoords = new Point3d[n]; for (int i = 0; i < n; i++) { originalCoords[i] = centers.get(i); transformedCoords[i] = new Point3d(); } } }
private void initialize() { // translation to centered coordinate system centroid = new Vector3d(subunits.getCentroid()); // translation back to original coordinate system Vector3d reverse = new Vector3d(centroid); reverse.negate(); centroidInverse.set(reverse); // Make sure matrix element m33 is 1.0. An old version vecmath did not set this element. centroidInverse.setElement(3, 3, 1.0); List<Point3d> centers = subunits.getCenters(); int n = subunits.getSubunitCount(); originalCoords = new Point3d[n]; transformedCoords = new Point3d[n]; for (int i = 0; i < n; i++) { originalCoords[i] = centers.get(i); transformedCoords[i] = new Point3d(); } setupDistanceBox(); } }
public void setFinalLeadIn(FramePoint finalPosition, FrameVector finalDirection, double approachDistance) { this.finalPosition.set(finalPosition); this.finalDirection.set(finalDirection); this.finalDirection.normalize(); this.finalDirection.get(tempVector); tempVector.negate(); GeometryTools.getAxisAngleFromZUpToVector(tempVector, tempAxisAngle); finalDistortionPose.setToZero(this.finalPosition.getReferenceFrame()); finalDistortionPose.setPosition(finalPosition); finalDistortionPose.setOrientation(tempAxisAngle); this.approachDistance.set(approachDistance); }
private void calcTransformationBySymmetryAxes() { Vector3d[] axisVectors = new Vector3d[2]; axisVectors[0] = new Vector3d(principalRotationVector); axisVectors[1] = new Vector3d(referenceVector); // y,z axis centered at the centroid of the subunits Vector3d[] referenceVectors = new Vector3d[2]; referenceVectors[0] = new Vector3d(Z_AXIS); referenceVectors[1] = new Vector3d(Y_AXIS); transformationMatrix = alignAxes(axisVectors, referenceVectors); // combine with translation Matrix4d combined = new Matrix4d(); combined.setIdentity(); Vector3d trans = new Vector3d(subunits.getCentroid()); trans.negate(); combined.setTranslation(trans); transformationMatrix.mul(combined); // for cyclic geometry, set a canonical view for the Z direction if (rotationGroup.getPointGroup().startsWith("C")) { calcZDirection(); } }
private void calcTransformationByInertiaAxes() { Vector3d[] axisVectors = new Vector3d[2]; axisVectors[0] = new Vector3d(principalAxesOfInertia[0]); axisVectors[1] = new Vector3d(principalAxesOfInertia[1]); Vector3d[] referenceVectors = new Vector3d[2]; referenceVectors[0] = new Vector3d(Y_AXIS); referenceVectors[1] = new Vector3d(X_AXIS); // align inertia axes with y-x plane transformationMatrix = alignAxes(axisVectors, referenceVectors); // combine with translation Matrix4d translation = new Matrix4d(); translation.setIdentity(); Vector3d trans = new Vector3d(subunits.getCentroid()); trans.negate(); translation.setTranslation(trans); transformationMatrix.mul(translation); }
public EarthVector findPointReverseDirection(final EarthVector nextCoord, final double fraction) { // check for same point first if (equals(nextCoord)) { return new EarthVector(this); } // compute the vector normal to this vector and the input vector final Vector3d nextVector = nextCoord.getVector(); final Vector3d vec = new Vector3d(); vec.cross(ecfVector, nextVector); vec.negate(); // compute the fractional angle between this vector and the input vector final double phi = fraction * Math.acos(ecfVector.dot(nextVector) / (ecfVector.length() * nextVector.length())); // create the vector rotated through phi about the normal vector final Vector3d output = rotate(vec, phi); // now scale the output vector by interpolating the magnitudes // of this vector and the input vector output.normalize(); final double size = ((nextVector.length() - ecfVector.length()) * fraction) + ecfVector.length(); output.scale(size); return new EarthVector(output); }
private void calcTransformationBySymmetryAxes() { Vector3d[] axisVectors = new Vector3d[2]; axisVectors[0] = new Vector3d(principalRotationVector); axisVectors[1] = new Vector3d(referenceVector); // y,z axis centered at the centroid of the subunits Vector3d[] referenceVectors = new Vector3d[2]; referenceVectors[0] = new Vector3d(Z_AXIS); referenceVectors[1] = new Vector3d(Y_AXIS); transformationMatrix = alignAxes(axisVectors, referenceVectors); // combine with translation Matrix4d combined = new Matrix4d(); combined.setIdentity(); Vector3d trans = new Vector3d(subunits.getCentroid()); trans.negate(); combined.setTranslation(trans); transformationMatrix.mul(combined); // for helical geometry, set a canonical view for the Z direction calcZDirection(); }
/** * Computes and sets the camera rotation for given camera position and a given point to focus on. * @param cameraPosition desired camera position. Not modified. * @param focusPoint desired focus position. Not modified. * @param cameraRoll desired camera roll. */ public void setRotationFromCameraAndFocusPositions(Point3d cameraPosition, Point3d focusPoint, double cameraRoll) { Vector3d fromFocusToCamera = new Vector3d(); fromFocusToCamera.sub(cameraPosition, focusPoint); fromFocusToCamera.normalize(); Vector3d fromCameraToFocus = new Vector3d(); fromCameraToFocus.negate(fromFocusToCamera); // We remove the component along up to be able to compute the longitude fromCameraToFocus.scaleAdd(-fromCameraToFocus.dot(up), up, fromCameraToFocus); double newLatitude = Math.PI / 2.0 - fromFocusToCamera.angle(up); double newLongitude = fromCameraToFocus.angle(forward); Vector3d cross = new Vector3d(); cross.cross(fromCameraToFocus, forward); if (cross.dot(up) > 0.0) newLongitude = -newLongitude; latitude.set(newLatitude); longitude.set(newLongitude); roll.set(cameraRoll); updateRotation(); }
private static MultiPolygonList2d applyWindowsEnd(MultiPolygonList2d mPoly, BuildingNodeElement be, Point2d segmentStart, Vector2d segmentDirection, double nodeDisplacement, CatchFaceFactory catchFaceFactory, BuildingElementsTextureManager textureMenager, boolean counterClockwise) { if (be instanceof SquareHoleElement) { SquareHoleElement she = (SquareHoleElement) be; Point2d lbp = new Point2d(nodeDisplacement - she.getWidth() / 2.0, she.getMinHeight()); Point2d mbp = new Point2d(nodeDisplacement, she.getMinHeight()); Point2d mtp = new Point2d(nodeDisplacement, she.getMaxHeight()); Point2d ltp = new Point2d(nodeDisplacement - she.getWidth() / 2.0, she.getMaxHeight()); mPoly = PolygonSplitHelper.unionOfLeftSideOfMultipleCuts(mPoly, new LinePoints2d(lbp, ltp), new LinePoints2d(ltp, mtp), new LinePoints2d(mbp, lbp)); TextureData td = findWindowTextureData(be, textureMenager); MeshFactory mesh = catchFaceFactory.createOrGetMeshFactory(td.getTex0()); FaceFactory face = mesh.addFace(FaceType.QUADS); Vector3d n = new Vector3d(-segmentDirection.y, 0, -segmentDirection.x); n.negate(); int iN = mesh.addNormal(n); int imbTc = mesh.addTextCoord(new TextCoord(0.5, 0)); int imtTc = mesh.addTextCoord(new TextCoord(0.5, 1)); int ilbTc = mesh.addTextCoord(new TextCoord(0, 0)); int iltTc = mesh.addTextCoord(new TextCoord(0, 1)); face.addVert(segmentPointToVertex3dIndex(lbp, segmentStart, segmentDirection, mesh), ilbTc, iN); face.addVert(segmentPointToVertex3dIndex(mbp, segmentStart, segmentDirection, mesh), imbTc, iN); face.addVert(segmentPointToVertex3dIndex(mtp, segmentStart, segmentDirection, mesh), imtTc, iN); face.addVert(segmentPointToVertex3dIndex(ltp, segmentStart, segmentDirection, mesh), iltTc, iN); } return mPoly; }
private static MultiPolygonList2d applyWindowsBegin(MultiPolygonList2d mPoly, BuildingNodeElement be, Point2d segmentStart, Vector2d segmentDirection, double nodeDisplacement, CatchFaceFactory pCatchFaceFactory, BuildingElementsTextureManager pTextureMenager, boolean counterClockwise) { if (be instanceof SquareHoleElement) { SquareHoleElement she = (SquareHoleElement) be; Point2d mbp = new Point2d(0, she.getMinHeight()); Point2d rbp = new Point2d(she.getWidth() / 2.0, she.getMinHeight()); Point2d rtp = new Point2d(she.getWidth() / 2.0, she.getMaxHeight()); Point2d mtp = new Point2d(0, she.getMaxHeight()); mPoly = PolygonSplitHelper.unionOfLeftSideOfMultipleCuts(mPoly, new LinePoints2d(rtp, rbp), new LinePoints2d(mtp, rtp), new LinePoints2d(rbp, mbp)); TextureData td = findWindowTextureData(be, pTextureMenager); MeshFactory mesh = pCatchFaceFactory.createOrGetMeshFactory(td.getTex0()); FaceFactory face = mesh.addFace(FaceType.QUADS); Vector3d n = new Vector3d(-segmentDirection.y, 0, -segmentDirection.x); // if (counterClockwise) { n.negate(); // } int iN = mesh.addNormal(n); int imbTc = mesh.addTextCoord(new TextCoord(0.5, 0)); int imtTc = mesh.addTextCoord(new TextCoord(0.5, 1)); int irbTc = mesh.addTextCoord(new TextCoord(1, 0)); int irtTc = mesh.addTextCoord(new TextCoord(1, 1)); face.addVert(segmentPointToVertex3dIndex(mbp, segmentStart, segmentDirection, mesh), imbTc, iN); face.addVert(segmentPointToVertex3dIndex(rbp, segmentStart, segmentDirection, mesh), irbTc, iN); face.addVert(segmentPointToVertex3dIndex(rtp, segmentStart, segmentDirection, mesh), irtTc, iN); face.addVert(segmentPointToVertex3dIndex(mtp, segmentStart, segmentDirection, mesh), imtTc, iN); } return mPoly; }