From 010cb5853a315bedc09834956614e802ca7a3775 Mon Sep 17 00:00:00 2001 From: rxbn_ Date: Fri, 6 Dec 2019 19:06:51 +0100 Subject: [PATCH] Aufgabe 2.2 - Vector2D constructor --- src/break_out/model/Vector2D.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/break_out/model/Vector2D.java b/src/break_out/model/Vector2D.java index cf21599..2ec28b5 100644 --- a/src/break_out/model/Vector2D.java +++ b/src/break_out/model/Vector2D.java @@ -32,6 +32,18 @@ public class Vector2D implements IVector2D { this.dy = dy; } + /** + * This constructor creates a new vector based on the given positions start and end. + * + * @param start first position + * @param end second position + */ + public Vector2D(Position start, Position end) { + // vector(AB) = (B.x - A.x, B.y - A.y) + this.dx = end.getX() - start.getX(); + this.dy = end.getY() - start.getY(); + } + /** * Getter for the dx-part *