From f1053aa2b01dc30aa1981dd9b59fb5cfde2d109e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Daleng?= <142524365+MrMarHVD@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:26:08 +0100 Subject: [PATCH] Created class Vector2D. --- .idea/misc.xml | 1 - .idea/vcs.xml | 6 ++ .../java/edu/ntnu/stud/model/Vector2D.java | 67 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/edu/ntnu/stud/model/Vector2D.java diff --git a/.idea/misc.xml b/.idea/misc.xml index ecfa09c..b173c63 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="MavenProjectsManager"> diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/src/main/java/edu/ntnu/stud/model/Vector2D.java b/src/main/java/edu/ntnu/stud/model/Vector2D.java new file mode 100644 index 0000000..89148ac --- /dev/null +++ b/src/main/java/edu/ntnu/stud/model/Vector2D.java @@ -0,0 +1,67 @@ +package edu.ntnu.stud.model; + +/** + * Class representing a 2D vector. + */ +public class Vector2D { + + /** + * The x0 component of the vector. + */ + private double x0; + + /** + * The x1 component of the vector. + */ + private double x1; + + /** + * Create a new 2D vector. + * + * @param x0 The x0 component of the vector. + * @param x1 The x1 component of the vector. + */ + public Vector2D(double x0, double x1) { + this.x0 = x0; + this.x1 = x1; + } + + /** + * Get the x0 component of the vector. + * + * @return The x0 component of the vector. + */ + public double getX0() { + return x0; + } + + /** + * Get the x1 component of the vector. + * + * @return The x1 component of the vector. + */ + public double getX1() { + return x1; + } + + /** + * Add another vector to this vector. + * + * @param other The other vector to add. + * @return A new vector that is the sum of this vector and the other vector. + */ + public Vector2D add(Vector2D other) { + return new Vector2D(x0 + other.x0, x1 + other.x1); + } + + /** + * Subtract another vector from this vector. + * + * @param other The other vector to subtract. + * @return A new vector that is the difference between this vector and the other vector. + */ + public Vector2D subtract(Vector2D other) { + return new Vector2D(x0 - other.x0, x1 - other.x1); + } + +} -- GitLab