/** * Transform all points with a 4x4 transformation matrix. * * @param rotTrans * 4x4 transformation matrix * @param x * array of points. Point objects will be modified */ public static void transform(Matrix4d rotTrans, Point3d[] x) { for (Point3d p : x) { rotTrans.transform(p); } }
/** * Use the given GMatrix to transform the given points inplace. * * @param m4d * the matrix to use (e.g. the inverse matrix or the forward matrix. * @param srcPts * The array containing the source point coordinates. */ private void transform( Matrix4d m4d, List<Point3d> srcPts ) { for ( Point3d p : srcPts ) { m4d.transform( p ); } }
public void transform(Point3f point) { Matrix4d matrix = this.matrixStack.peek(); matrix.transform(point); }
public void transform(Vector3f point) { Matrix4d matrix = this.matrixStack.peek(); matrix.transform(point); }
/** * Applies the transformation to given point. */ public void transformPoint(final double[] point) { Point3d p = new Point3d(point[0],point[1],point[2]); transformation.transform(p); point[0] = p.x; point[1] = p.y; point[2] = p.z; }
public Point3f getTranslation() { Matrix4d matrix = this.matrixStack.peek(); Point3f translation = new Point3f(); matrix.transform(translation); return translation; }
private List<Point3d> interiorCenters(List<Point3d> points) { Matrix4d transformation = helixAxisAligner.getTransformation(); Matrix4d reversetransformation = helixAxisAligner.getReverseTransformation(); List<Point3d> ePoints = new ArrayList<Point3d>(points.size()); for (Point3d p: points) { Point3d q = new Point3d(p); transformation.transform(q); q.x = 0; q.z = 0; reversetransformation.transform(q); ePoints.add(q); } return ePoints; }
private Point3d[] getPolyhedronVertices() { Point3d[] vertices = polyhedron.getVertices(); Matrix4d reverseTransformation = rotationAxisAligner.getGeometicCenterTransformation(); for (int i = 0; i < vertices.length; i++) { reverseTransformation.transform(vertices[i]); } return vertices; }
private List<Point3d> extendUnitCenters(List<Point3d> points) { Matrix4d transformation = helixAxisAligner.getTransformation(); Matrix4d reversetransformation = helixAxisAligner.getReverseTransformation(); double radius = helixAxisAligner.getRadius(); radius += SIDE_CHAIN_EXTENSION; // add space for side chains // System.out.println("XZRadius: " + radius); List<Point3d> ePoints = new ArrayList<Point3d>(points.size()); for (Point3d p: points) { Point3d q = new Point3d(p); transformation.transform(q); double d = Math.sqrt(q.x*q.x + q.z*q.z); double scale = radius/d; q.x *= scale; q.z *= scale; reversetransformation.transform(q); ePoints.add(q); } return ePoints; }
/** * Orients layer lines from lowest y-axis value to largest y-axis value */ private List<List<Integer>> orientLayerLines(List<List<Integer>> layerLines) { Matrix4d transformation = helixAxisAligner.getTransformation(); List<Point3d> centers = helixAxisAligner.getSubunits().getOriginalCenters(); for (int i = 0; i < layerLines.size(); i++) { List<Integer> layerLine = layerLines.get(i); // get center of first subunit in layerline and transform to standard orientation (helix axis aligned with y-axis) int first = layerLine.get(0); Point3d firstSubunit = new Point3d(centers.get(first)); transformation.transform(firstSubunit); // get center of last subunit in layerline and transform to standard orientation (helix axis aligned with y-axis) int last = layerLine.get(layerLine.size()-1); Point3d lastSubunit = new Point3d(centers.get(last)); transformation.transform(lastSubunit); // a layerline should start at the lowest y-value, so all layerlines have a consistent direction from -y value to +y value if (firstSubunit.y > lastSubunit.y) { // System.out.println("reorienting layer line: " + layerLine); Collections.reverse(layerLine); } } return layerLines; }
@Override public ResultSample doTransformVectorTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4d m1 = vecMatrixRandom(); final Vector3d v1 = new Vector3d(1, 2, 3); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.transform(v1); } } return populateResult(System.currentTimeMillis() - start, loopCount, toArray(v1)); }
@Override public ResultSample doTransformPointTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4d m1 = vecMatrixRandom(); final Point3d p1 = new Point3d(1, 2, 3); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.transform(p1); } } return populateResult(System.currentTimeMillis() - start, loopCount, toArray(p1)); }
private double[] getSubunitXYWidth() { int n = subunits.getSubunitCount(); double[] width = new double[n]; Point3d probe = new Point3d(); // transform subunit centers into z-aligned position and calculate // width in xy direction. for (int i = 0; i < n; i++) { width[i] = Double.MIN_VALUE; for (Point3d p: subunits.getTraces().get(i)) { probe.set(p); transformationMatrix.transform(probe); width[i] = Math.max(width[i], Math.sqrt(probe.x*probe.x + probe.y*probe.y)); } } return width; }
private double[] getSubunitZDepth() { int n = subunits.getSubunitCount(); double[] depth = new double[n]; Point3d probe = new Point3d(); // transform subunit centers into z-aligned position and calculate // z-coordinates (depth) along the z-axis. for (int i = 0; i < n; i++) { Point3d p= subunits.getCenters().get(i); probe.set(p); transformationMatrix.transform(probe); depth[i] = probe.z; } return depth; }
private double[] getSubunitZDepth() { int n = subunits.getSubunitCount(); double[] depth = new double[n]; Point3d probe = new Point3d(); // transform subunit centers into z-aligned position and calculate // z-coordinates (depth) along the z-axis. for (int i = 0; i < n; i++) { Point3d p= subunits.getCenters().get(i); probe.set(p); transformationMatrix.transform(probe); depth[i] = probe.z; } return depth; }
@Override public Point3d getGeometricCenter() { run(); Point3d geometricCenter = new Point3d(); Vector3d translation = new Vector3d(); // reverseTransformationMatrix.get(translation); // TODO does this apply to the helic case? // calculate adjustment around z-axis and transform adjustment to // original coordinate frame with the reverse transformation // Vector3d corr = new Vector3d(0,minBoundary.y+getDimension().y, 0); // reverseTransformationMatrix.transform(corr); // geometricCenter.set(corr); reverseTransformationMatrix.transform(translation); geometricCenter.add(translation); return geometricCenter; }
/** * Transforms an atom object, given a Matrix4d (i.e. the vecmath library * double-precision 4x4 rotation+translation matrix). The transformation * Matrix must be a post-multiplication Matrix. * * @param atom * @param m */ public static final void transform (Atom atom, Matrix4d m) { Point3d p = new Point3d(atom.getX(),atom.getY(),atom.getZ()); m.transform(p); atom.setX(p.x); atom.setY(p.y); atom.setZ(p.z); }
private Vector3d getSubunitReferenceVector() { int n = subunits.getSubunitCount(); Point3d probe = new Point3d(); // transform subunit centers into z-aligned position and calculate // width in xy direction. double maxWidthSq = 0; Point3d ref = null; for (int i = 0; i < n; i++) { for (Point3d p: subunits.getTraces().get(i)) { probe.set(p); transformationMatrix.transform(probe); double widthSq = probe.x*probe.x + probe.y*probe.y; if (widthSq > maxWidthSq) { maxWidthSq = widthSq; ref = p; } } } // System.out.println("width: " + maxWidthSq); Vector3d refVector = new Vector3d(); refVector.sub(ref, subunits.getCentroid()); refVector.normalize(); return refVector; }
/** * Returns the geometric center of polyhedron. In the case of the Cn * point group, the centroid and geometric center are usually not * identical. * @return */ @Override public Point3d getGeometricCenter() { run(); Point3d geometricCenter = new Point3d(); Vector3d translation = new Vector3d(); reverseTransformationMatrix.get(translation); // calculate adjustment around z-axis and transform adjustment to // original coordinate frame with the reverse transformation if (rotationGroup.getPointGroup().startsWith("C")) { Vector3d corr = new Vector3d(0,0, minBoundary.z+getDimension().z); reverseTransformationMatrix.transform(corr); geometricCenter.set(corr); } geometricCenter.add(translation); return geometricCenter; }
private static Vector3d[] getPolygonVertices(Vector3d axis, Vector3d referenceAxis, Point3d center, int n, double radius) { Vector3d ref = new Vector3d(referenceAxis); ref.scale(radius); AxisAngle4d axisAngle = new AxisAngle4d(axis, 0); Vector3d[] vectors = new Vector3d[n]; Matrix4d m = new Matrix4d(); for (int i = 0; i < n; i++) { axisAngle.angle = i * 2 * Math.PI/n; vectors[i] = new Vector3d(ref); m.set(axisAngle); // make sure matrix element m33 is 1.0. It's 0 on Linux. m.setElement(3, 3, 1.0); m.transform(vectors[i]); vectors[i].add(center); } return vectors; }