/** * Computes the average 2D point from a given collection of 2D points. * <p> * WARNING: This method generates garbage. * </p> * * @param points the collection of 2D points to compute the average from. Not modified. * @return the computed average. */ public static Point2d averagePoint2ds(Collection<Point2d> points) { Point2d totalPoint = new Point2d(0.0, 0.0); for (Point2d point : points) { totalPoint.add(point); } totalPoint.scale(1.0 / points.size()); return totalPoint; }
public void setAngle(double angle) { Point2d point = findEdgePoint(angle); point.scale(getEccentricity()); set(point); }
/** * Multiplies all the coordinates of the atoms of the given molecule with the scalefactor. See * comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) * for details on coordinate sets * * @param atomCon The molecule to be scaled * @param scaleFactor Description of the Parameter */ public static void scaleMolecule(IAtomContainer atomCon, double scaleFactor) { for (int i = 0; i < atomCon.getAtomCount(); i++) { if (atomCon.getAtom(i).getPoint2d() != null) { atomCon.getAtom(i).getPoint2d().scale(scaleFactor); } } // scale Sgroup brackets if (atomCon.getProperty(CDKConstants.CTAB_SGROUPS) != null) { List<Sgroup> sgroups = atomCon.getProperty(CDKConstants.CTAB_SGROUPS); for (Sgroup sgroup : sgroups) { List<SgroupBracket> brackets = sgroup.getValue(SgroupKey.CtabBracket); if (brackets != null) { for (SgroupBracket bracket : brackets) { bracket.getFirstPoint().scale(scaleFactor); bracket.getSecondPoint().scale(scaleFactor); } } } } }
/** * Scale this convex polygon about pointToScaleAbout. * @param scaleFactor */ public void scale(Point2d pointToScaleAbout, double scaleFactor) { checkIfUpToDate(); for (int i = 0; i < numberOfVertices; i++) { Point2d vertex = getVertexUnsafe(i); vertex.sub(pointToScaleAbout); vertex.scale(scaleFactor); vertex.add(pointToScaleAbout); } update(); }
midPoint.scale(0.5);
@Override public void doControl() { // update the linear momentum rate by numerical differentiation of the robot momentum simulatedRobot.getRootJoint().physics.recursiveComputeLinearMomentum(linearMomentum); yoLinearMomentum.set(linearMomentum); momentumChange.update(); momentumChange.get(linearMomentumRate); // get mass and COM position from the robot double totalMass = simulatedRobot.computeCenterOfMass(comPosition); comPosition2d.set(comPosition.getX(), comPosition.getY()); // now compute the COM acceleration comAcceleration.set(linearMomentumRate.getX(), linearMomentumRate.getY()); comAcceleration.scale(1.0 / totalMass); // CMP = COM - 1/omega^2 * COMAcc double omega0 = Math.sqrt(-gravity / comPosition.getZ()); cmp.set(comAcceleration); cmp.scale(- 1.0 / (omega0 * omega0)); cmp.add(comPosition2d); yoCmp.set(cmp); }
@Override public void doControl() { // update the linear momentum rate by numerical differentiation of the robot momentum simulatedRobot.getRootJoint().physics.recursiveComputeLinearMomentum(linearMomentum); yoLinearMomentum.set(linearMomentum); momentumChange.update(); momentumChange.get(linearMomentumRate); // get mass and COM position from the robot double totalMass = simulatedRobot.computeCenterOfMass(comPosition); comPosition2d.set(comPosition.getX(), comPosition.getY()); // now compute the COM acceleration comAcceleration.set(linearMomentumRate.getX(), linearMomentumRate.getY()); comAcceleration.scale(1.0 / totalMass); // CMP = COM - 1/omega^2 * COMAcc double omega0 = Math.sqrt(-gravity / comPosition.getZ()); cmp.set(comAcceleration); cmp.scale(- 1.0 / (omega0 * omega0)); cmp.add(comPosition2d); yoCmp.set(cmp); }
for (Point2d polygonPoint : clockwiseOrderedConvexPolygonPoints) average.add(polygonPoint); average.scale(1.0 / N);
centroid.scale(1.0 / numberOfVertices);