Example #1
0
 private double doubleVectorAbs(Vector<Vector<Double>> doubleVector) {
   double totalX = 0;
   for (Vector<Double> vector : doubleVector) {
     totalX += Math.pow(vectorAbs(vector), 2);
   }
   return Math.sqrt(totalX);
 }
Example #2
0
    /**
     * Calculates the unit normal of a particular vector, where the vector is represented by the
     * direction and magnitude of the line segment from (0,0) to (p.x, p.y).
     *
     * @param p
     * @return
     */
    private static Point2D vectorUnitNormal(Point2D p) {
      // if null object passed or if the passed vector has zero length
      if (null == p || ((0 == p.getX()) && (0 == p.getY()))) {
        return null;
      }

      // normalise the input "vector"
      // 1. get length of vector (Pythagoras)
      // 2. divide both x and y by this length
      // note: c cannot be 0 as we've already considered zero length input
      // vectors above.
      double c = Math.sqrt((p.getX() * p.getX()) + (p.getY() * p.getY()));
      double nvx = p.getX() / c;
      double nvy = p.getY() / c;

      // Now rotate (nvx, nvy) by 90 degrees to get the normal for the
      // input vector.
      // rx = nvx * cos (pi/2) - nvy * sin (pi/2)
      // ty = nvx * sin (pi/2) + nvy * cos (pi/2)
      // but cos (pi/2) = 0 and sin (pi/2) = 1, so this simplifies
      return new Point2D.Float((float) (-1 * nvy), (float) nvx);
    }
Example #3
0
 private double vectorAbs(Vector<Double> vector) {
   double totalX = 0;
   for (Double x : vector) totalX += Math.pow(x, 2);
   return Math.sqrt(totalX);
 }