public Point3d getCenterOfMass() { if (points.size() == 0) { throw new IllegalStateException( "MomentsOfInertia: no points defined"); } Point3d center = new Point3d(); double totalMass = 0.0; for (int i = 0, n = points.size(); i < n; i++) { double mass = masses.get(i); totalMass += mass; center.scaleAdd(mass, points.get(i), center); } center.scale(1.0 / totalMass); return center; }
public Point3d getMeanPoint() { Point3d pointMean = new Point3d(); for(int i=0;i<points.size();i++) { pointMean.add(points.get(i)); } pointMean.scale(1.0/points.size()); return pointMean; } }
private static int segmentPointToVertex3dIndex(Point2d point, Point2d start, Vector2d direction, MeshFactory mesh) { Point3d vertex = new Point3d(direction.x, 0, -direction.y); vertex.scale(point.x); vertex.x += start.x; vertex.z -= start.y; vertex.y = point.y; int iV = mesh.addVertex(vertex); return iV; }
/** * Computes the average 3D point from a given collection of 3D points. * <p> * WARNING: This method generates garbage. * </p> * * @param points the collection of 3D points to compute the average from. Not modified. * @return the computed average. */ public static Point3d averagePoint3ds(Collection<Point3d> points) { Point3d totalPoint = new Point3d(0.0, 0.0, 0.0); for (Point3d point : points) { totalPoint.add(point); } totalPoint.scale(1.0 / points.size()); return totalPoint; }
/** * Calculate the centroid of the point cloud. * * @param x * array of points. Point objects will not be modified * @return centroid as Point3d */ public static Point3d centroid(Point3d[] x) { Point3d center = new Point3d(); for (Point3d p : x) { center.add(p); } center.scale(1.0 / x.length); return center; }
/** * Returns the average of two 3D points. * <p> * WARNING: This method generates garbage. * </p> * * @param a the first 3D point. Not modified. * @param b the second 3D point. Not modified. * @return the computed average. */ public static Point3d averagePoints(Point3d a, Point3d b) { Point3d average = new Point3d(a); average.add(b); average.scale(0.5); return average; }
public Point3d getAveragePoint() { if (averagePoint == null) { averagePoint = new Point3d(Double.NaN, Double.NaN, Double.NaN); } if (Double.isNaN(averagePoint.getX())) { averagePoint.set(0.0, 0.0, 0.0); int numberOfPoints = points.size(); for (int i = 0; i < numberOfPoints; i++) { averagePoint.add(points.get(i)); } averagePoint.scale(1.0 / ((double) numberOfPoints)); } return averagePoint; }
private String drawInertiaAxes() { StringBuilder s = new StringBuilder(); Point3d centroid = rotationAxisAligner.getGeometricCenter(); Vector3d[] axes = rotationAxisAligner.getPrincipalAxesOfInertia(); for (int i = 0; i < axes.length; i++) { s.append("draw axesInertia"); s.append(name); s.append(i); s.append(" "); s.append("line"); Point3d v1 = new Point3d(axes[i]); if (i == 0) { v1.scale(AXIS_SCALE_FACTOR*rotationAxisAligner.getDimension().y); } else if (i == 1) { v1.scale(AXIS_SCALE_FACTOR*rotationAxisAligner.getDimension().x); } else if (i == 2) { v1.scale(AXIS_SCALE_FACTOR*rotationAxisAligner.getDimension().z); } Point3d v2 = new Point3d(v1); v2.negate(); v1.add(centroid); v2.add(centroid); s.append(getJmolPoint(v1)); s.append(getJmolPoint(v2)); s.append("width 0.5 "); s.append(" color white"); s.append(" off;"); } return s.toString(); };
p.scale(1.0/count);
s.append("line"); Point3d v1 = new Point3d(axis); v1.scale(AXIS_SCALE_FACTOR*(helixAxisAligner.getDimension().y + SIDE_CHAIN_EXTENSION)); Point3d v2 = new Point3d(v1); v2.negate();
centerOfRotation.scale(1/(line.size()-2));
faceCenter.scale(1.0 / numPoints); plane.setPoint(faceCenter); plane.setNormal(planeNormal);
result.scale(sign * scale); result.add(facePoint); return result;
private void calculateCenters() { localCenter = new Point3d(boxVector); localCenter.scale(0.5); rootCenter = new Point3d(localCenter); forwardTransform.transform(rootCenter); forwardCenterTransform = new Transform3D(forwardTransform); forwardCenterTransform.mul(toTransform(new Vector3d(localCenter))); reverseCenterTransform = new Transform3D(forwardCenterTransform); reverseCenterTransform.invert(); }
projectedPoints.add(projectedPoint); averagePoint.scale(1.0 / facePoints.size()); polygonPose.getPoint().set(averagePoint);
/** * Gets the center coordinates of the unit's BoundingBox in the unit coordinate system as a Point3d object. * * @param unitConfig the unit config to refer the unit. * @return center coordinates of the unit's BoundingBox relative to unit * @throws NotAvailableException is thrown if the center can not be calculate. */ default Point3d getUnitBoundingBoxCenterPoint3d(final UnitConfig unitConfig) throws NotAvailableException { final AxisAlignedBoundingBox3DFloatType.AxisAlignedBoundingBox3DFloat bb = getUnitShape(unitConfig).getBoundingBox(); final TranslationType.Translation lfc = bb.getLeftFrontBottom(); final Point3d center = new Point3d(bb.getWidth(), bb.getDepth(), bb.getHeight()); center.scale(0.5); center.add(new Point3d(lfc.getX(), lfc.getY(), lfc.getZ())); return center; }
private Point3d getMidFootPoint() { RigidBodyTransform temp = new RigidBodyTransform(); Point3d left = new Point3d(); Point3d avg = new Point3d(); fullRobotModel.getFoot(RobotSide.LEFT).getBodyFixedFrame().getTransformToDesiredFrame(temp, ReferenceFrame.getWorldFrame()); temp.transform(left); fullRobotModel.getFoot(RobotSide.RIGHT).getBodyFixedFrame().getTransformToDesiredFrame(temp, ReferenceFrame.getWorldFrame()); temp.transform(avg); avg.add(left); avg.scale(0.5); return avg; }
tempLeftFootPose.getPosition(temp); pointBetweenFeet.add(temp); pointBetweenFeet.scale(0.5);
pointOnIntersectionToPack.setY(d1 * normal3Cross2Y + d2 * normal1Cross3Y + d3 * normal2Cross1Y); pointOnIntersectionToPack.setZ(d1 * normal3Cross2Z + d2 * normal1Cross3Z + d3 * normal2Cross1Z); pointOnIntersectionToPack.scale(-1.0 / det);
rightFootPose.getPosition(temp); pointBetweenFeet.add(temp); pointBetweenFeet.scale(0.5);