/**
   * Rotate the oriented bounding box of the 3D image about the specified axis with the specified
   * angle.
   *
   * @param transform The transform and its matrix by which to rotate the image.
   */
  public void rotateFrameBy(Transform3D transform) {

    double rY, rX, rZ;
    double sinrX, sinrY, sinrZ, cosrX, cosrY, cosrZ;
    Matrix3d matrix = new Matrix3d();

    transform.get(matrix);

    rY = -Math.asin(matrix.m02);

    if (Math.cos(rY) != 0) {
      rX = -Math.atan2(matrix.m12, matrix.m22);
      rZ = Math.atan2(matrix.m01, matrix.m00);
    } else {
      rX = -Math.atan2(matrix.m10, matrix.m11);
      rZ = 0;
    }

    cosrX = Math.cos(rX);
    sinrX = Math.sin(rX);
    cosrY = Math.cos(rY);
    sinrY = Math.sin(rY);
    cosrZ = Math.cos(rZ);
    sinrZ = Math.sin(rZ);

    matrix.m00 = cosrZ * cosrY;
    matrix.m01 = -sinrZ * cosrY;
    matrix.m02 = sinrY;

    matrix.m10 = (cosrZ * sinrY * sinrX) + (sinrZ * cosrX);
    matrix.m11 = (-sinrZ * sinrY * sinrX) + (cosrZ * cosrX);
    matrix.m12 = -cosrY * sinrX;

    matrix.m20 = (-cosrZ * sinrY * cosrX) + (sinrZ * sinrX);
    matrix.m21 = (sinrZ * sinrY * cosrX) + (cosrZ * sinrX);
    matrix.m22 = cosrY * cosrX;

    m_kRotate.set(matrix);
    m_akAxis[0] = new Vector3f(1.0f, 0.0f, 0.0f);
    m_akAxis[1] = new Vector3f(0.0f, 1.0f, 0.0f);
    m_akAxis[2] = new Vector3f(0.0f, 0.0f, 1.0f);

    for (int i = 0; i < 3; i++) {
      m_kRotate.transform(m_akAxis[i]);
    }

    orthonormalize(m_akAxis);

    for (int i = 0; i < 3; i++) {
      setAxis(i, m_akAxis[i]);
    }
  }
  public static Vector3f rotate(Vector3f v, Vector3f axis, float angle) {
    // Rotate the point (x,y,z) around the vector (u,v,w)
    // Function RotatePointAroundVector(x#,y#,z#,u#,v#,w#,a#)
    float ux = axis.x * v.x;
    float uy = axis.x * v.y;
    float uz = axis.x * v.z;
    float vx = axis.y * v.x;
    float vy = axis.y * v.y;
    float vz = axis.y * v.z;
    float wx = axis.z * v.x;
    float wy = axis.z * v.y;
    float wz = axis.z * v.z;
    float sa = (float) Math.sin(angle);
    float ca = (float) Math.cos(angle);
    float x =
        axis.x * (ux + vy + wz)
            + (v.x * (axis.y * axis.y + axis.z * axis.z) - axis.x * (vy + wz)) * ca
            + (-wy + vz) * sa;
    float y =
        axis.y * (ux + vy + wz)
            + (v.y * (axis.x * axis.x + axis.z * axis.z) - axis.y * (ux + wz)) * ca
            + (wx - uz) * sa;
    float z =
        axis.z * (ux + vy + wz)
            + (v.z * (axis.x * axis.x + axis.y * axis.y) - axis.z * (ux + vy)) * ca
            + (-vx + uy) * sa;

    return new Vector3f(x, y, z);
  }
  /**
   * Return a midpoint of a helix, calculated from three positions of three adjacent subunit
   * centers.
   *
   * @param p1 center of first subunit
   * @param p2 center of second subunit
   * @param p3 center of third subunit
   * @return midpoint of helix
   */
  private Point3d getMidPoint(Point3d p1, Point3d p2, Point3d p3) {
    Vector3d v1 = new Vector3d();
    v1.sub(p1, p2);
    Vector3d v2 = new Vector3d();
    v2.sub(p3, p2);
    Vector3d v3 = new Vector3d();
    v3.add(v1);
    v3.add(v2);
    v3.normalize();

    // calculat the total distance between to subunits
    double dTotal = v1.length();
    // calculate the rise along the y-axis. The helix axis is aligned with y-axis,
    // therfore, the rise between subunits is the y-distance
    double rise = p2.y - p1.y;
    // use phythagorean theoremm to calculate chord length between two subunit centers
    double chord = Math.sqrt(dTotal * dTotal - rise * rise);
    //		System.out.println("Chord d: " + dTotal + " rise: " + rise + "chord: " + chord);
    double angle = helixLayers.getByLargestContacts().getAxisAngle().angle;

    // using the axis angle and the chord length, we can calculate the radius of the helix
    // http://en.wikipedia.org/wiki/Chord_%28geometry%29
    double radius = chord / Math.sin(angle / 2) / 2; // can this go to zero?
    //		System.out.println("Radius: " + radius);

    // project the radius onto the vector that points toward the helix axis
    v3.scale(radius);
    v3.add(p2);
    //		System.out.println("Angle: " +
    // Math.toDegrees(helixLayers.getByLowestAngle().getAxisAngle().angle));
    Point3d cor = new Point3d(v3);
    return cor;
  }
  /** Move up/down a given distance. */
  public void translateUpDown(double d) {
    if (globe == null || d == 0) return;
    double hDist = d * Math.cos(Math.PI / 2. + ha);
    double vDist = d * Math.sin(Math.PI / 2. + ha);

    lla = globe.getEllipsoid().forwGeodesic(lat, lon, hDist, az, lla);
    lat = lla.lat;
    lon = lla.lon;
    az = Ellipsoid.adjlonPos(lla.az + Math.PI);
    hEllps += vDist;
    ele_changed = lat_changed = lon_changed = az_changed = true;
    h = Double.MAX_VALUE;
  }
  public void translate(double d, double t_az, double t_ha, boolean correct_az) {
    if (globe == null || d == 0) return;
    double hDist = d * Math.cos(t_ha);
    double vDist = d * Math.sin(t_ha);

    lla = globe.getEllipsoid().forwGeodesic(lat, lon, hDist, t_az, lla);
    lat = lla.lat;
    lon = lla.lon;
    hEllps += vDist;
    if (correct_az) {
      az = Ellipsoid.adjlonPos(az + lla.az + Math.PI - t_az);
      az_changed = true;
    }
    ele_changed = lat_changed = lon_changed = true;
    h = Double.MAX_VALUE;
  }
Exemple #6
0
 protected void computeCircle() {
   Vector3d center = new Vector3d((Vector3d) get(0));
   Vector3d p2 = new Vector3d((Vector3d) get(1));
   p2.sub(center);
   double radius = p2.length();
   removeAllElements();
   double angle = 0;
   double incAngle = 2 * Math.PI / sides;
   for (int i = 0; i < sides; i++) {
     super.add(
         new Vector3d(
             center.x + radius * Math.cos(angle), center.y + radius * Math.sin(angle), 0));
     angle += incAngle;
   }
   super.add(new Vector3d(center.x + radius, center.y, 0));
 }
  public void rotateAroundPointer(double x_rot, double y_rot) {
    if (hTerrain < 0) hTerrain = 0;
    if (Math.abs(point_dist * Math.sin(x_rot)) > hTerrain / 10)
      x_rot = Math.asin(hTerrain / point_dist / 10) * (x_rot >= 0 ? 1 : -1);
    if (Math.abs(point_dist * Math.sin(y_rot)) > hTerrain / 10)
      y_rot = Math.asin(hTerrain / point_dist / 10) * (y_rot >= 0 ? 1 : -1);

    // translateSideway(dist*Math.sin(x_rot))
    double d_x = point_dist * Math.sin(x_rot);
    lla = globe.getEllipsoid().forwGeodesic(lat, lon, -d_x * Math.cos(ha), az + Math.PI / 2., lla);
    lat = lla.lat;
    lon = lla.lon;
    az = Ellipsoid.adjlonPos(lla.az + Math.PI / 2.);

    // translateUpDown(dist*Math.sin(y_rot));
    double d_y = point_dist * Math.sin(y_rot);
    hEllps += d_y * Math.sin(Math.PI / 2. + ha);
    lla = globe.getEllipsoid().forwGeodesic(lat, lon, d_y * Math.cos(Math.PI / 2. + ha), az, lla);
    lat = lla.lat;
    lon = lla.lon;
    az = Ellipsoid.adjlonPos(lla.az + Math.PI);

    // translateForward(dist*(1-Math.cos(x_rot))*(1-Math.cos(y_rot)));
    double d_xy = point_dist * (1 - Math.cos(x_rot)) * (1 - Math.cos(y_rot));
    hEllps += d_xy * Math.sin(ha);
    lla = globe.getEllipsoid().forwGeodesic(lat, lon, d_xy * Math.cos(ha), az, lla);
    lat = lla.lat;
    lon = lla.lon;
    az = Ellipsoid.adjlonPos(lla.az + Math.PI + x_rot);

    ha -= y_rot;
    if (ha > Math.PI / 2) ha = Math.PI / 2;
    if (ha < -Math.PI / 2) ha = -Math.PI / 2;
    ele_changed = lat_changed = lon_changed = az_changed = ha_changed = true;
    h = Double.MAX_VALUE;
  }
Exemple #8
0
  private void createSections() {
    float axonRadius = .5f;

    Point3f posnEndPoint = new Point3f(0, -15, 0);

    Segment rootAxon =
        addAxonalSegment(axonRadius, "root", posnEndPoint, somaSection, 1, "axonRootSec");

    Vector<Segment> layer = new Vector<Segment>();

    layer.add(addRelativeAxon(rootAxon, new Point3f(-30, -20, -30), axonRadius));
    layer.add(addRelativeAxon(rootAxon, new Point3f(-30, -20, 30), axonRadius));
    layer.add(addRelativeAxon(rootAxon, new Point3f(30, -20, 30), axonRadius));
    layer.add(addRelativeAxon(rootAxon, new Point3f(30, -20, -30), axonRadius));

    for (int i = 0; i < layer.size(); i++) {
      Segment axon = (Segment) layer.elementAt(i);
      Segment a1 = addRelativeAxon(axon, new Point3f(-6, -4, -6), axonRadius);
      Segment a2 = addRelativeAxon(axon, new Point3f(6, -4, -6), axonRadius);
      Segment a3 = addRelativeAxon(axon, new Point3f(-6, -4, 6), axonRadius);
      Segment a4 = addRelativeAxon(axon, new Point3f(6, -4, 6), axonRadius);

      a1.getSection().addToGroup(axonSynGroup);
      a2.getSection().addToGroup(axonSynGroup);
      a3.getSection().addToGroup(axonSynGroup);
      a4.getSection().addToGroup(axonSynGroup);
    }

    float dendriteDiam = 2;

    int numDendrites = 6;

    for (int i = 0; i < numDendrites; i++) {
      double theta = ((2 * Math.PI) / numDendrites) * i;

      float xFact = (float) Math.sin(theta);
      float zFact = (float) Math.cos(theta);

      posnEndPoint = new Point3f(60 * xFact, 60, 60 * zFact);
      Segment radialDend =
          addDendriticSegment(
              dendriteDiam,
              "radialDend_" + i,
              posnEndPoint,
              somaSection,
              0,
              "radialDend_" + i + "_Sec",
              false);

      Point3f posnNew = new Point3f(30 * xFact, 40, 30 * zFact);
      Segment radialDend2 = addRelativeDendrite(radialDend, posnNew);
      radialDend2.getSection().addToGroup(dendSynGroup);
      Point3f posnNew2 = new Point3f(0, 30, 0);
      Segment radialDend3 = addRelativeDendrite(radialDend2, posnNew2);

      radialDend3.getSection().addToGroup(dendSynGroup);

      Point3f posnNew3 = new Point3f(-10 * xFact, 30, -10 * zFact);
      Segment radialDend4 = addRelativeDendrite(radialDend, posnNew3);

      radialDend4.getSection().addToGroup(dendSynGroup);
      Point3f posnNew4 = new Point3f(0, 25, 0);
      Segment radialDend5 = addRelativeDendrite(radialDend4, posnNew4);

      radialDend5.getSection().addToGroup(dendSynGroup);
    }
  }