Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Collection;
- import java.util.Iterator;
- /**
- *
- * @author Tomaz
- */
- public class GeometricVector {
- public static GeometricVector valueOf(Point3D start, Point3D end) {
- return new GeometricVector(start, end);
- }
- public static double length(Collection<Point3D> pontos) {
- if (pontos.size() < 2)
- return 0D;
- double distancia = 0D;
- Iterator<Point3D> itr = pontos.iterator();
- Point3D start = itr.next();
- Point3D end;
- for (; itr.hasNext() ;) {
- end = itr.next();
- distancia += valueOf(start, end).length();
- start = end;
- }
- return distancia;
- }
- private final Point3D start;
- private final Point3D end;
- public GeometricVector(Point3D start, Point3D end) {
- this.start = start;
- this.end = end;
- }
- public Point3D getStart() {
- return start;
- }
- public Point3D getEnd() {
- return end;
- }
- public double length() {
- double xDeltaPow2 = Math.pow(
- end.getX().doubleValue()-start.getX().doubleValue(), 2);
- double yDeltaPow2 = Math.pow(
- end.getY().doubleValue()-start.getY().doubleValue(), 2);
- double zDeltaPow2 = Math.pow(
- end.getZ().doubleValue()-start.getZ().doubleValue(), 2);
- return Math.sqrt(xDeltaPow2 + yDeltaPow2 + zDeltaPow2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment