private int findPointOfMinMov(int start_, int end_, int fileIndex) { // logger.debug("Anfang: " + start_+ " Ende: " + end_); int start = start_; // double sum = Math.pow(rawData.get(fileIndex).getDimension(0)[start],2) + // Math.pow(rawData.get(fileIndex).getDimension(1)[start],2) + // Math.pow(rawData.get(fileIndex).getDimension(2)[start],2); // sum = Math.sqrt(sum); Point3d from = new Point3d( rawData.get(fileIndex).getDimension(0)[start], rawData.get(fileIndex).getDimension(1)[start], rawData.get(fileIndex).getDimension(2)[start]); int minMovIndex = start; while (start != end_) { // mean of difference of acceleration to fixed point Point3d tempPoint = new Point3d( rawData.get(fileIndex).getDimension(0)[start], rawData.get(fileIndex).getDimension(1)[start], rawData.get(fileIndex).getDimension(2)[start]); // tempSum = Math.sqrt(tempSum); // if ((sum - tempSum > 0)){ // sum = tempSum; if (from.distance(tempPoint) < 0.2) { minMovIndex = start; // logger.debug("summe: " +minMovIndex); } start++; } return minMovIndex; }
/* * Bottom up hierarchical clustering */ private static HashSet<Cluster> findClusters(Collection<Point3d> points, double threshold) { HashSet<Cluster> clusters = new HashSet<>(points.size() * 2); for (Point3d p : points) { Cluster candidate = new Cluster(); candidate.add(p); for (Point3d p2 : points) { if (p != p2 && p.distance(p2) <= threshold) { candidate.add(p2); } } Iterator<Cluster> iter = clusters.iterator(); while (iter.hasNext()) { Cluster c = iter.next(); for (Point3d p2 : candidate) { if (c.contains(p2)) { // Se os clusters C e candidate se intersectam, fundi-los candidate.addAll(c); iter.remove(); break; } } } clusters.add(candidate); } return clusters; }
// generic method for calculation of distance btw 2 atoms private double calculateDistanceBetweenTwoAtoms(IAtom atom1, IAtom atom2) { double distance; Point3d firstPoint = atom1.getPoint3d(); Point3d secondPoint = atom2.getPoint3d(); distance = firstPoint.distance(secondPoint); return distance; }
// method which calculated distance btw an atom and the middle point of a bond // and returns distance and coordinates of middle point private double[] calculateDistanceBetweenAtomAndBond(IAtom proton, IBond theBond) { Point3d middlePoint = theBond.get3DCenter(); Point3d protonPoint = proton.getPoint3d(); double[] values = new double[4]; values[0] = middlePoint.distance(protonPoint); values[1] = middlePoint.x; values[2] = middlePoint.y; values[3] = middlePoint.z; return values; }
/** * Tests if two positions are symmetrically equivalent under point group within a provided * tolerance. * * @param a First comparison Point3d. * @param b Second comparison Point3d * @param tolerance Tolerance distance * @return True if positions are equivalent, false otherwise. */ public boolean isSymmetricallyEquivalent(Point3d a, Point3d b, double tolerance) { boolean isequivalent = false; for (SymmetryOperation key : operations) { Point3d testcoord = key.transformPoint(a); if (testcoord.distance(b) < tolerance) { isequivalent = true; break; } } return isequivalent; }
public boolean isValidList2Position(Vector3d position) { for (int i = 0; i < pcList2.size(); i++) { PointCharge pc = (PointCharge) pcList2.get(i); Point3d pcPosition = new Point3d(pc.getPosition()); if (pcPosition.distance(new Point3d(position)) < pc_radius * 1.5) { return false; } } if (Math.abs(position.x - plate2_position.x) > plate_length / 2. - pc_radius) return false; if (Math.abs(position.y - plate2_position.y) > plate_height / 2. - pc_radius) return false; if (Math.abs(position.z - plate2_position.z) > plate_width / 2. - pc_radius) return false; return true; }
public void moveCamera() { try { cameraT3D.lookAt(cameraPos, cameraFocus, up); cameraT3D.invert(); cameraTG.setTransform(cameraT3D); // lamp position at camera camLamp.setPosition(new Point3f(cameraPos)); // camera distance to object camDist = cameraPos.distance(getObjCenter()); } catch (SingularMatrixException ex) { ex.printStackTrace(); } }
public boolean areSamePos(Point3d p1, Point3d p2) { return Math.abs(p1.distance(p2)) < epsilon; }
private void init(final Content c, final int x, final int y) { xLast = x; yLast = y; content = c; // some transforms c.getLocalToVworld(localToVWorld); localToVWorldInverse.invert(localToVWorld); canvas.getImagePlateToVworld(ipToVWorld); ipToVWorldInverse.invert(ipToVWorld); // calculate the canvas position in world coords c.getContent().getCenter(centerInVWorld); localToVWorld.transform(centerInVWorld); ipToVWorldInverse.transform(centerInVWorld, centerInIp); // get the eye point in world coordinates canvas.getCenterEyeInImagePlate(eyePtInVWorld); ipToVWorld.transform(eyePtInVWorld); // use picking to infer the radius of the virtual sphere which is rotated final Point3d p = univ.getPicker().getPickPointGeometry(c, x, y); float r = 0, dD = 0; if (p != null) { pickPtInVWorld.set(p); localToVWorld.transform(pickPtInVWorld); r = (float) pickPtInVWorld.distance(centerInVWorld); } else { c.getContent().getMin(p1); localToVWorld.transform(p1); r = (float) p1.distance(centerInVWorld); vec.sub(centerInVWorld, eyePtInVWorld); vec.normalize(); vec.scale(-r); pickPtInVWorld.add(centerInVWorld, vec); } dD = (float) pickPtInVWorld.distance(eyePtInVWorld); // calculate distance between eye and canvas point canvas.getPixelLocationInImagePlate(x, y, p1); ipToVWorld.transform(p1); final float dd = (float) p1.distance(eyePtInVWorld); // calculate the virtual distance between two neighboring pixels canvas.getPixelLocationInImagePlate(x + 1, y, p2); ipToVWorld.transform(p2); final float dx = (float) p1.distance(p2); // calculate the virtual distance between two neighboring pixels canvas.getPixelLocationInImagePlate(x, y + 1, p3); ipToVWorld.transform(p3); final float dy = (float) p1.distance(p3); final float dX = dD / dd * dx; final float dY = dD / dd * dy; anglePerPix = Math.atan2(dX, r); univ.getViewPlatformTransformer().getYDir(axisPerDx, ipToVWorld); univ.getViewPlatformTransformer().getXDir(axisPerDy, ipToVWorld); translationPerDx.set(axisPerDy); translationPerDx.scale(dX); translationPerDy.set(axisPerDx); translationPerDy.scale(dY); rotateTG = c.getLocalRotate(); translateTG = c.getLocalTranslate(); c.getContent().getCenter(vec); transl_inv.set(vec); vec.set(-vec.x, -vec.y, -vec.z); transl.set(vec); }
private MyPickResult getMouseIntersection(MouseEvent e, boolean withSnap) { MyPickResult myResult = new MyPickResult(); Point3d closestObjectPos = null; Point3d closestMarkPos = null; Node closestObject = null; Node closestMark = null; // 0: closest object; 1: closest mark pickCanvas.setShapeLocation(e); PickResult[] allResults = null; try { allResults = pickCanvas.pickAllSorted(); } catch (AssertionError ex) { } if (allResults != null) { for (PickResult result : allResults) { Shape3D s = (Shape3D) result.getNode(PickResult.SHAPE3D); if (s != null) { // only pick a Shape3D object if (closestObjectPos != null && closestMarkPos != null) { break; } try { PickIntersection intersection = result.getClosestIntersection(cameraPos); if (!(s.getParent().getParent().getParent() instanceof Mark) && !((s.getParent().getParent().getParent() instanceof Marker))) { // markdot/markline/label -> TG -> BG -> Mark/Marker try { closestObjectPos = intersection.getPointCoordinatesVW(); closestObject = s; } catch (NullPointerException ex) { } } else if ((s.getParent().getParent().getParent() instanceof Mark)) { try { closestMarkPos = intersection.getPointCoordinatesVW(); closestMark = s; } catch (NullPointerException ex) { } } } catch (NullPointerException ex) { } } } Point3d resultPos = null; Node resultNode = null; if (closestMark != null) { resultPos = closestMarkPos; // priority of result -> mark resultNode = closestMark; } else if (closestObject != null) { resultPos = closestObjectPos; resultNode = closestObject; } if (withSnap) { // snap resultPos to correct position // start trying to if cursor are inside object bounding sphere if ((closestObjectPos != null && bs.intersect(closestObjectPos)) || closestMarkPos != null && bs.intersect(closestMarkPos)) { Point3d closestObjectPos2 = null; Point3d closestMarkPos2 = null; Node closestObject2 = null; Node closestMark2 = null; // initiate snap bounds if hasn't been initiated before // "snappable" targets to be considered are the ones inside threshold if (cursorBound == null) { cursorBound = new BoundingSphere(resultPos, CURSOR_THRESHOLD); } if (thresholdBound == null) { thresholdBound = new BoundingSphere(resultPos, SNAP_THRESHOLD); } // update the bounds // only if the cursor is no longer inside current cursor bounds if (!cursorBound.intersect(resultPos)) { cursorBound.setCenter(resultPos); thresholdBound.setCenter(resultPos); } // snap to nearest point in the list of snap targets double nearestDistance = FARTHEST; double distance; Point3d nearestTarget = null; // snap to vertex. all vertexes listed in snapList if (snapList.size() > 0) { for (Point3d snapTarget : snapList) { if (thresholdBound.intersect(snapTarget)) { distance = snapTarget.distance(resultPos); if (distance < nearestDistance) { nearestDistance = distance; nearestTarget = snapTarget; } if (nearestTarget != null) { resultPos.set(nearestTarget); // snap! // pick the snapped node Vector3d camToSnapped = new Vector3d(); camToSnapped.x = resultPos.x - cameraPos.x; camToSnapped.y = resultPos.y - cameraPos.y; camToSnapped.z = resultPos.z - cameraPos.z; pickCanvas.setShapeRay(cameraPos, camToSnapped); PickResult[] allResultsSnapped = null; try { allResultsSnapped = pickCanvas.pickAllSorted(); } catch (AssertionError ex) { } if (allResultsSnapped != null) { for (PickResult result : allResultsSnapped) { Shape3D s = (Shape3D) result.getNode(PickResult.SHAPE3D); if (s != null) { // only pick a Shape3D object if (closestObjectPos2 != null && closestMarkPos2 != null) { break; } try { PickIntersection intersection = result.getClosestIntersection(cameraPos); if (!(s.getParent().getParent().getParent() instanceof Mark) && !((s.getParent().getParent().getParent() instanceof Marker))) { // markdot/markline/label -> TG -> BG -> Mark/Marker try { closestObjectPos2 = intersection.getPointCoordinatesVW(); closestObject2 = s; } catch (NullPointerException ex) { } } else if ((s.getParent().getParent().getParent() instanceof Mark)) { try { closestMarkPos2 = intersection.getPointCoordinatesVW(); closestMark2 = s; } catch (NullPointerException ex) { } } } catch (NullPointerException ex) { } } } if (closestMark2 != null) { resultPos = closestMarkPos2; // priority of result -> mark resultNode = closestMark2; } else if (closestObject2 != null) { resultPos = closestObjectPos2; resultNode = closestObject2; } } } } } } } } myResult.setPoint(resultPos); myResult.setNode(resultNode); } return myResult; }