javax.vecmath.Point3d Java Examples

The following examples show how to use javax.vecmath.Point3d. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystematicSolver.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
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();
	}
}
 
Example #2
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * ���E���\�z
 */
private void createSceneGraph() {
    // sceneBG�ɂ��낢��ڑ����邱�ƂŐ��E���\�������
    sceneBG = new BranchGroup();
    // ���E�͈̔́i�����Ȃǂ̋y�Ԕ͈́j
    bounds = new BoundingSphere(new Point3d(0, 0, 0), BOUND_SIZE);

    lightScene(); // ������sceneBG�ɒlj�
    addBackground(); // ���sceneBG�ɒlj�

    // ���W����lj�
    Axis axis = new Axis();
    sceneBG.addChild(axis.getBG());

    sceneBG.compile();
}
 
Example #3
Source File: CalcPoint.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the TM-Score for two superimposed sets of coordinates Yang Zhang
 * and Jeffrey Skolnick, PROTEINS: Structure, Function, and Bioinformatics
 * 57:702–710 (2004)
 *
 * @param x
 *            coordinate set 1
 * @param y
 *            coordinate set 2
 * @param lengthNative
 *            total length of native sequence
 * @return
 */
public static double TMScore(Point3d[] x, Point3d[] y, int lengthNative) {

	if (x.length != y.length) {
		throw new IllegalArgumentException(
				"Point arrays are not of the same length.");
	}

	double d0 = 1.24 * Math.cbrt(x.length - 15.0) - 1.8;
	double d0Sq = d0 * d0;

	double sum = 0;
	for (int i = 0; i < x.length; i++) {
		sum += 1.0 / (1.0 + x[i].distanceSquared(y[i]) / d0Sq);
	}

	return sum / lengthNative;
}
 
Example #4
Source File: JDOMUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static Element writePoint3dList(final String tagName, final ArrayList<Point3d> pts) {
  if (pts == null) {
    return null;
  } else {
    final StringBuffer sb = new StringBuffer();

    final int nPts = pts.size();
    int idx = 0;
    for (final Point3d pt : pts) {
      sb.append(Double.toString(pt.x));
      sb.append(",");
      sb.append(Double.toString(pt.y));
      sb.append(",");
      sb.append(Double.toString(pt.z));

      if (idx < (nPts - 1)) {
        sb.append(",");
      }

      idx++;
    }

    return writeStringVal(tagName, sb.toString());
  }
}
 
Example #5
Source File: Grid.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
public boolean hasAnyContact(Collection<Point3d> atoms) {
	for(Point3d atom : atoms) {
		// Calculate Grid cell for the atom
		int xind = xintgrid2xgridindex(getFloor(atom.x));
		int yind = yintgrid2ygridindex(getFloor(atom.y));
		int zind = zintgrid2zgridindex(getFloor(atom.z));

		// Consider 3x3x3 grid of cells around point
		for (int x=xind-1;x<=xind+1;x++) {
			if( x<0 || cells.length<=x) continue;
			for (int y=yind-1;y<=yind+1;y++) {
				if( y<0 || cells[x].length<=y ) continue;
				for (int z=zind-1;z<=zind+1;z++) {
					if( z<0 || cells[x][y].length<=z ) continue;

					GridCell cell = cells[x][y][z];
					// Check for contacts in this cell
					if(cell != null && cell.hasContactToAtom(iAtoms, jAtoms, atom, cutoff)) {
						return true;
					}
				}
			}
		}
	}
	return false;
}
 
Example #6
Source File: StructureToProteinDimers.java    From mmtf-spark with Apache License 2.0 6 votes vote down vote up
private static List<DistanceBox<Integer>> getAllAtomsDistanceBoxes(List<StructureDataInterface> chains, double cutoffDistance)
{
	List<DistanceBox<Integer>> distanceBoxes = new ArrayList<DistanceBox<Integer>>();
	for(int i = 0; i < chains.size(); i++)
	{
		StructureDataInterface tmp = chains.get(i);
		DistanceBox<Integer> newBox = new DistanceBox<Integer>(cutoffDistance);
		//System.out.println(tmp.getNumAtoms());
		for(int j = 0; j <tmp.getNumAtoms(); j++)
		{
			double xCoord = tmp.getxCoords()[j];
			double yCoord = tmp.getyCoords()[j];
			double zCoord = tmp.getzCoords()[j];
			Point3d newPoint = new Point3d(xCoord, yCoord, zCoord);
			//System.out.println(newPoint);
			newBox.addPoint(newPoint, j);
		}
		distanceBoxes.add(newBox);
	}
	return distanceBoxes;
}
 
Example #7
Source File: RectangularPrism.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the vertices of an n-fold polygon of given radius and center
 * @param n
 * @param radius
 * @param center
 * @return
 */
@Override
public Point3d[] getVertices() {
	double x = 0.5 * width;
	double y = 0.5 * height;
	double z = 0.5 * length;
	Point3d[] vertices = new Point3d[8];
	vertices[0] = new Point3d(-x, -y,  z);
	vertices[1] = new Point3d(-x,  y,  z);
	vertices[2] = new Point3d( x,  y,  z);
	vertices[3] = new Point3d( x, -y,  z);
	vertices[4] = new Point3d(-x, -y, -z);
	vertices[5] = new Point3d(-x,  y, -z);
	vertices[6] = new Point3d( x,  y, -z);
	vertices[7] = new Point3d( x, -y, -z);

	return vertices;
}
 
Example #8
Source File: Java3DWindow.java    From GpsPrune with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a text object for compass point, N S E or W
 * @param inText text to display
 * @param inLocn position at which to display
 * @param inFont 3d font to use
 * @return compound object
 */
private TransformGroup createCompassPoint(String inText, Point3f inLocn, Font3D inFont)
{
	Text3D txt = new Text3D(inFont, inText, inLocn, Text3D.ALIGN_FIRST, Text3D.PATH_RIGHT);
	Material mat = new Material(new Color3f(0.5f, 0.5f, 0.55f),
		new Color3f(0.05f, 0.05f, 0.1f), new Color3f(0.3f, 0.4f, 0.5f),
		new Color3f(0.4f, 0.5f, 0.7f), 70.0f);
	mat.setLightingEnable(true);
	Appearance app = new Appearance();
	app.setMaterial(mat);
	Shape3D shape = new Shape3D(txt, app);

	// Make transform group with billboard behaviour
	TransformGroup subGroup = new TransformGroup();
	subGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
	subGroup.addChild(shape);
	Billboard billboard = new Billboard(subGroup, Billboard.ROTATE_ABOUT_POINT, inLocn);
	BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
	billboard.setSchedulingBounds(bounds);
	subGroup.addChild(billboard);
	return subGroup;
}
 
Example #9
Source File: TestInterfaceFinder.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
private List<Group> getGroupList(int size, String type, Chain chain, Point3d center) {
    List<Group> list = new ArrayList<>();
    double offsetx = 0;
    double offsety = 0;
    double offsetz = 0;
    for (int i=0;i<size;i++) {
        Group g = new AminoAcidImpl();
        g.setPDBName(type);
        g.setResidueNumber(new ResidueNumber(chain.getId(), i+1, null));
        chain.addGroup(g);
        Atom a = new AtomImpl();
        a.setName(StructureTools.CA_ATOM_NAME);
        a.setX(center.x + offsetx);
        a.setY(center.y + offsety);
        a.setZ(center.z + offsetz);
        g.addAtom(a);
        list.add(g);

        if (i%3 == 0) offsetx += 1;
        if (i%3 == 1) offsety += 1;
        if (i%3 == 2) offsetz += 1;
    }

    return list;
}
 
Example #10
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * ���[�U�̎��_��������
 */
private void initUserPosition() {
    ViewingPlatform vp = universe.getViewingPlatform(); // SimpleUniverse�̃f�t�H���g���擾
    TransformGroup steerTG = vp.getViewPlatformTransform(); // vp��TG���擾

    Transform3D t3d = new Transform3D(); // ���_�ivp�j�ړ��p��T3D
    steerTG.getTransform(t3d); // ���݂̎��_���擾

    // �V�������_��ݒ�
    // ���[�U�̈ʒu�A������̍��W�A�������w��
    // ���_�̐�͌��_
    t3d.lookAt(USER_POS, new Point3d(0, 0, 0), new Vector3d(0, 1, 0));
    t3d.invert();

    steerTG.setTransform(t3d); // �ύX�������_��ݒ�
}
 
Example #11
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the geometric center of all the atoms in this atomContainer. See
 * comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param ac Description of the Parameter
 * @return the geometric center of the atoms in this atomContainer
 */
public static Point3d get3DCenter(IAtomContainer ac) {
    double centerX = 0;
    double centerY = 0;
    double centerZ = 0;
    double counter = 0;
    Iterator<IAtom> atoms = ac.atoms().iterator();
    while (atoms.hasNext()) {
        IAtom atom = (IAtom) atoms.next();
        if (atom.getPoint3d() != null) {
            centerX += atom.getPoint3d().x;
            centerY += atom.getPoint3d().y;
            centerZ += atom.getPoint3d().z;
            counter++;
        }
    }
    return new Point3d(centerX / (counter), centerY / (counter), centerZ / (counter));
}
 
Example #12
Source File: SuperPositionQCP.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Calculates the RMSD value for superposition of y onto x. This requires
 * the coordinates to be precentered.
 *
 * @param x
 *            3d points of reference coordinate set
 * @param y
 *            3d points of coordinate set for superposition
 */
private void calcRmsd(Point3d[] x, Point3d[] y) {
	if (centered) {
		innerProduct(y, x);
	} else {
		// translate to origin
		xref = CalcPoint.clonePoint3dArray(x);
		xtrans = CalcPoint.centroid(xref);
		logger.debug("x centroid: " + xtrans);
		xtrans.negate();
		CalcPoint.translate(new Vector3d(xtrans), xref);

		yref = CalcPoint.clonePoint3dArray(y);
		ytrans = CalcPoint.centroid(yref);
		logger.debug("y centroid: " + ytrans);
		ytrans.negate();
		CalcPoint.translate(new Vector3d(ytrans), yref);
		innerProduct(yref, xref);
	}
	calcRmsd(wsum);
}
 
Example #13
Source File: Skycam.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void render(GL2 gl2) {
	gl2.glPushMatrix();
	MatrixHelper.applyMatrix(gl2, pose);
	Vector3d s = size.get();
	Vector3d pos = getPosition();
	Point3d bottom = new Point3d(pos.x-s.x/2,pos.y-s.y/2,pos.z);
	Point3d top   = new Point3d(pos.x+s.x/2,pos.y+s.y/2,pos.z+s.z);
	PrimitiveSolids.drawBoxWireframe(gl2, bottom,top);
	
	Vector3d ep = ee.getPosition();
	gl2.glBegin(GL2.GL_LINES);
	gl2.glVertex3d(ep.x,ep.y,ep.z);  gl2.glVertex3d(bottom.x,bottom.y,top.z);
	gl2.glVertex3d(ep.x,ep.y,ep.z);  gl2.glVertex3d(bottom.x,top   .y,top.z);
	gl2.glVertex3d(ep.x,ep.y,ep.z);  gl2.glVertex3d(top   .x,top   .y,top.z);
	gl2.glVertex3d(ep.x,ep.y,ep.z);  gl2.glVertex3d(top   .x,bottom.y,top.z);
	gl2.glEnd();
	
	gl2.glPopMatrix();
	
	super.render(gl2);
}
 
Example #14
Source File: DragBallEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
protected void renderTranslationHandle(GL2 gl2,Vector3d n) {
	// draw line to box
	gl2.glBegin(GL2.GL_LINES);
	gl2.glVertex3d(0,0,0);
	gl2.glVertex3d(n.x,n.y,n.z);
	gl2.glEnd();

	// draw box
	Point3d b0 = new Point3d(+0.05,+0.05,+0.05); 
	Point3d b1 = new Point3d(-0.05,-0.05,-0.05);

	b0.scale(1);
	b1.scale(1);
	b0.add(n);
	b1.add(n);
	PrimitiveSolids.drawBox(gl2, b0,b1);
}
 
Example #15
Source File: Grid.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Adds a set of coordinates, subsequent call to {@link #getIndicesContacts()} will produce the
 * contacts, i.e. the set of points within distance cutoff.
 * The bounds calculated elsewhere can be passed, or if null they are computed.
 * Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException
 * since this only adds coordinates and no atom information.
 * @param atoms
 * @param bounds
 */
public void addCoords(Point3d[] atoms, BoundingBox bounds) {
	this.iAtoms = atoms;
	this.iAtomObjects = null;

	if (bounds!=null) {
		this.ibounds = bounds;
	} else {
		this.ibounds = new BoundingBox(iAtoms);
	}

	this.jAtoms = null;
	this.jAtomObjects = null;
	this.jbounds = null;

	fillGrid();
}
 
Example #16
Source File: UnitQuaternions.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The orientation represents the rotation of the principal axes with
 * respect to the axes of the coordinate system (unit vectors [1,0,0],
 * [0,1,0] and [0,0,1]).
 * <p>
 * The orientation can be expressed as a unit quaternion.
 *
 * @param points
 *            array of Point3d
 * @return the orientation of the point cloud as a unit quaternion
 */
public static Quat4d orientation(Point3d[] points) {

	MomentsOfInertia moi = new MomentsOfInertia();

	for (Point3d p : points)
		moi.addPoint(p, 1.0);

	// Convert rotation matrix to quaternion
	Quat4d quat = new Quat4d();
	quat.set(moi.getOrientationMatrix());

	return quat;
}
 
Example #17
Source File: IntersectionTester.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
static protected double[] SATTest(Vector3d normal, Point3d[] corners) {
	double[] values = new double[2];
	values[0] =  Double.MAX_VALUE; // min value
	values[1] = -Double.MAX_VALUE; // max value

	for (int i = 0; i < corners.length; ++i) {
		double dotProduct = corners[i].x * normal.x + corners[i].y * normal.y + corners[i].z * normal.z;
		if (values[0] > dotProduct) values[0] = dotProduct;
		if (values[1] < dotProduct) values[1] = dotProduct;
	}

	return values;
}
 
Example #18
Source File: AtomImpl.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public AtomImpl () {
	name       = null;
	element    = Element.R;
	coords	   = new Point3d();
	occupancy  = 0.0f;
	tempfactor = 0.0f;
	altLoc 	   = 0;
	parent     = null;
	bonds      = null; // let's save some memory and let's not initialise this until it's needed - JD 2016-03-02
	charge     = 0;
}
 
Example #19
Source File: InteractionCenter.java    From mmtf-spark with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor using columnar structure with an atom index.
 * 
 * @param structure
 *            columnar structure
 * @param atomIndex
 *            index to the interacting atom
 */
public InteractionCenter(ColumnarStructureX structure, int atomIndex) {
    this.setAtomName(structure.getAtomNames()[atomIndex]);
    this.setElement(structure.getElements()[atomIndex]);
    this.setGroupName(structure.getGroupNames()[atomIndex]);
    this.setGroupNumber(structure.getGroupNumbers()[atomIndex]);
    this.setType(structure.getEntityTypes()[atomIndex]);
    this.setChainName(structure.getChainNames()[atomIndex]);
    this.setSequencePosition(structure.getSequencePositions()[atomIndex]);
    this.setCoordinates(new Point3d(structure.getxCoords()[atomIndex], structure.getyCoords()[atomIndex],
            structure.getzCoords()[atomIndex]));
    this.setNormalizedbFactor(structure.getNormalizedbFactors()[atomIndex]);
}
 
Example #20
Source File: JDOMUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static Point3d readPoint3d(final String tagName, final Element parentEl) {
  final Element ptEl = parentEl.getChild(tagName);

  if (ptEl == null) {
    return null;
  } else {
    final double x = getDoubleVal(ptEl, JDOMUtils.tagX);
    final double y = getDoubleVal(ptEl, JDOMUtils.tagY);
    final double z = getDoubleVal(ptEl, JDOMUtils.tagZ);

    return new Point3d(x, y, z);
  }
}
 
Example #21
Source File: DragBallEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
protected double testBoxHit(Ray ray,Vector3d n) {		
	Point3d b0 = new Point3d(); 
	Point3d b1 = new Point3d();

	b0.set(+0.05,+0.05,+0.05);
	b1.set(-0.05,-0.05,-0.05);
	b0.scale(ballSize.get());
	b1.scale(ballSize.get());
	b0.add(n);
	b1.add(n);
	
	return MathHelper.rayBoxIntersection(ray,b0,b1);
}
 
Example #22
Source File: Calc.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert an array of atoms into an array of vecmath points
 *
 * @param atoms
 *            list of atoms
 * @return list of Point3ds storing the x,y,z coordinates of each atom
 */
public static Point3d[] atomsToPoints(Atom[] atoms) {
	Point3d[] points = new Point3d[atoms.length];
	for(int i = 0; i< atoms.length;i++) {
		points[i] = atoms[i].getCoordsAsPoint3d();
	}
	return points;
}
 
Example #23
Source File: BoundingBox.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Check if a given point falls within this box
 * @param atom
 * @return
 */
public boolean contains(Point3d atom) {
	double x = atom.x;
	double y = atom.y;
	double z = atom.z;
	return xmin <= x && x <= xmax
			&& ymin <= y && y <= ymax
			&& zmin <= z && z <= zmax;
}
 
Example #24
Source File: InterfaceFinder.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void initBoundingBoxes() {
    List<Chain> polyChains = structure.getPolyChains();
    boundingBoxes = new BoundingBox[polyChains.size()];
    for (int i = 0; i<polyChains.size(); i++) {
        Atom[] atoms = StructureTools.getAllNonHAtomArray(polyChains.get(i), INCLUDE_HETATOMS);
        Point3d[] points = Calc.atomsToPoints(atoms);
        BoundingBox bb = new BoundingBox(points);
        boundingBoxes[i] = bb;
    }
}
 
Example #25
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * ���E���\�z
 */
private void createSceneGraph() {
    // sceneBG�ɂ��낢��ڑ����邱�ƂŐ��E���\�������
    sceneBG = new BranchGroup();
    // ���E�͈̔́i�����Ȃǂ̋y�Ԕ͈́j
    bounds = new BoundingSphere(new Point3d(0, 0, 0), BOUND_SIZE);

    lightScene(); // ������sceneBG�ɒlj�
    addBackground(); // ���sceneBG�ɒlj�
    addSphere(); // ����lj�

    sceneBG.compile();
}
 
Example #26
Source File: HelicalRepeatUnit.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static int calcContactNumber(Point3d[] a, Point3d[] b) {
	int contacts = 0;
	for (Point3d pa : a) {
		for (Point3d pb : b) {
			if (pa.distance(pb) < 10) {
				contacts++;
			}
		}
	}
	return contacts;
}
 
Example #27
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the atoms which are closes to an atom in an AtomContainer by
 * distance in 3d.
 *
 * @param container The AtomContainer to examine
 * @param startAtom the atom to start from
 * @param max the number of neighbours to return
 * @return the average bond length
 * @exception CDKException Description of the Exception
 */
public static List<IAtom> findClosestInSpace(IAtomContainer container, IAtom startAtom, int max)
        throws CDKException {
    Point3d originalPoint = startAtom.getPoint3d();
    if (originalPoint == null) {
        throw new CDKException("No point3d, but findClosestInSpace is working on point3ds");
    }
    Map<Double, IAtom> atomsByDistance = new TreeMap<Double, IAtom>();
    for (IAtom atom : container.atoms()) {
        if (!atom.equals(startAtom)) {
            if (atom.getPoint3d() == null) {
                throw new CDKException("No point3d, but findClosestInSpace is working on point3ds");
            }
            double distance = atom.getPoint3d().distance(originalPoint);
            atomsByDistance.put(distance, atom);
        }
    }
    // FIXME: should there not be some sort here??
    Set<Double> keySet = atomsByDistance.keySet();
    Iterator<Double> keyIter = keySet.iterator();
    List<IAtom> returnValue = new ArrayList<IAtom>();
    int i = 0;
    while (keyIter.hasNext() && i < max) {
        returnValue.add(atomsByDistance.get(keyIter.next()));
        i++;
    }
    return (returnValue);
}
 
Example #28
Source File: Calc.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: TestUnitQuaternions.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test {@link UnitQuaternions#relativeOrientation(Point3d[], Point3d[])} on
 * a real structure. Test recovering of the angle applied.
 *
 * @throws StructureException
 * @throws IOException
 */
@Test
public void testRelativeOrientation() throws IOException,
		StructureException {

	// Get points from a structure.
	Structure pdb = StructureIO.getStructure("4hhb.A");
	Point3d[] cloud = Calc.atomsToPoints(StructureTools
			.getRepresentativeAtomArray(pdb));
	Point3d[] cloud2 = CalcPoint.clonePoint3dArray(cloud);

	// Test orientation angle equal to 0 at this point
	double angle = UnitQuaternions.orientationAngle(cloud, cloud2, false);
	assertEquals(angle, 0, 0.001);

	// Apply a 30 degree rotation to cloud
	AxisAngle4d axis = new AxisAngle4d(new Vector3d(1,1,1), Math.PI / 6);
	Matrix4d transform = new Matrix4d();
	transform.set(axis);

	CalcPoint.transform(transform, cloud);
	angle = UnitQuaternions.orientationAngle(cloud, cloud2, false);
	angle = Math.min(Math.abs(2 * Math.PI - angle), angle);

	// Test that angle was recovered
	assertEquals(angle, Math.PI / 6, 0.001);
}
 
Example #30
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the center of mass for the <code>Atom</code>s in the
 * AtomContainer for the 2D coordinates. See comment for
 * center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param ac AtomContainer for which the center of mass is calculated
 * @return Description of the Return Value
 * @cdk.keyword center of mass
 * @cdk.dictref blue-obelisk:calculate3DCenterOfMass
 */
public static Point3d get3DCentreOfMass(IAtomContainer ac) {
    double xsum = 0.0;
    double ysum = 0.0;
    double zsum = 0.0;

    double totalmass = 0.0;

    Iterator<IAtom> atoms = ac.atoms().iterator();
    while (atoms.hasNext()) {
        IAtom a = (IAtom) atoms.next();
        Double mass = a.getExactMass();
        // some sanity checking
        if (a.getPoint3d() == null) {
            return null;
        }
        if (mass == null) {
            return null;
        }

        totalmass += mass;
        xsum += mass * a.getPoint3d().x;
        ysum += mass * a.getPoint3d().y;
        zsum += mass * a.getPoint3d().z;
    }

    return new Point3d(xsum / totalmass, ysum / totalmass, zsum / totalmass);
}