/** * Creates a vector from a {@link Coordinate}. * * @param coord * the Coordinate to copy * @return a new vector */ public static Vector3D create(Coordinate coord) { return new Vector3D(coord); }
/** * Creates a new vector with given X and Y components. * * @param x * the x component * @param y * the y component * @param z * the z component * @return a new vector */ public static Vector3D create(double x, double y, double z) { return new Vector3D(x, y, z); }
/** * Computes the oriented distance from a point to the plane. * The distance is: * <ul> * <li><b>positive</b> if the point lies above the plane (relative to the plane normal) * <li><b>zero</b> if the point is on the plane * <li><b>negative</b> if the point lies below the plane (relative to the plane normal) * </ul> * * @param p the point to compute the distance for * @return the oriented distance to the plane */ public double orientedDistance(Coordinate p) { Vector3D pb = new Vector3D(p, basePt); double pbdDotNormal = pb.dot(normal); if (Double.isNaN(pbdDotNormal)) throw new IllegalArgumentException("3D Coordinate has NaN ordinate"); double d = pbdDotNormal / normal.length(); return d; }
/** * Creates a vector from a {@link Coordinate}. * * @param coord * the Coordinate to copy * @return a new vector */ public static Vector3D create(Coordinate coord) { return new Vector3D(coord); }
/** * Creates a new vector with given X and Y components. * * @param x * the x component * @param y * the y component * @param z * the z component * @return a new vector */ public static Vector3D create(double x, double y, double z) { return new Vector3D(x, y, z); }
/** * Computes the oriented distance from a point to the plane. * The distance is: * <ul> * <li><b>positive</b> if the point lies above the plane (relative to the plane normal) * <li><b>zero</b> if the point is on the plane * <li><b>negative</b> if the point lies below the plane (relative to the plane normal) * </ul> * * @param p the point to compute the distance for * @return the oriented distance to the plane */ public double orientedDistance(Coordinate p) { Vector3D pb = new Vector3D(p, basePt); double pbdDotNormal = pb.dot(normal); if (Double.isNaN(pbdDotNormal)) throw new IllegalArgumentException("3D Coordinate has NaN ordinate"); double d = pbdDotNormal / normal.length(); return d; }
/** * Get the vector with the highest down slope in the plan. * @param normal * @param epsilon * @return the steepest vector. */ public static Vector3D getSteepestVector(final Vector3D normal, final double epsilon) { if (Math.abs(normal.getX()) < epsilon && Math.abs(normal.getY()) < epsilon) { return new Vector3D(0, 0, 0); } Vector3D slope; if (Math.abs(normal.getX()) < epsilon) { slope = new Vector3D(0, 1, -normal.getY() / normal.getZ()); } else if (Math.abs(normal.getY()) < epsilon) { slope = new Vector3D(1, 0, -normal.getX() / normal.getZ()); } else { slope = new Vector3D(normal.getX() / normal.getY(), 1, -1 / normal.getZ() * (normal.getX() * normal.getX() / normal.getY() + normal.getY())); } //We want the vector to be low-oriented. if (slope.getZ() > epsilon) { slope = new Vector3D(-slope.getX(), -slope.getY(), -slope.getZ()); } //We normalize it return slope.normalize(); }
/** * Get the vector with the highest down slope in the plan. * @param normal * @param epsilon * @return the steepest vector. */ public static Vector3D getSteepestVector(final Vector3D normal, final double epsilon) { if (Math.abs(normal.getX()) < epsilon && Math.abs(normal.getY()) < epsilon) { return new Vector3D(0, 0, 0); } Vector3D slope; if (Math.abs(normal.getX()) < epsilon) { slope = new Vector3D(0, 1, -normal.getY() / normal.getZ()); } else if (Math.abs(normal.getY()) < epsilon) { slope = new Vector3D(1, 0, -normal.getX() / normal.getZ()); } else { slope = new Vector3D(normal.getX() / normal.getY(), 1, -1 / normal.getZ() * (normal.getX() * normal.getX() / normal.getY() + normal.getY())); } //We want the vector to be low-oriented. if (slope.getZ() > epsilon) { slope = new Vector3D(-slope.getX(), -slope.getY(), -slope.getZ()); } //We normalize it return slope.normalize(); }
Vector3D vector = new Vector3D(normal.getX(), normal.getY(), 0).normalize(); for(LineSegment side : sides) { Coordinate intersection = CoordinateUtils.vectorIntersection(inCenter, vector, side.p0, new Vector3D(side.p0,side.p1).normalize()); double distInters = intersection == null ? Double.MAX_VALUE : side.distance(intersection); if(intersection != null && distInters < nearestIntersection) {
Vector3D vector = new Vector3D(normal.getX(), normal.getY(), 0).normalize(); for(LineSegment side : sides) { Coordinate intersection = CoordinateUtils.vectorIntersection(inCenter, vector, side.p0, new Vector3D(side.p0,side.p1).normalize()); double distInters = intersection == null ? Double.MAX_VALUE : side.distance(intersection); if(intersection != null && distInters < nearestIntersection) {