Skip to content
Snippets Groups Projects
Commit f1053aa2 authored by Håvard Daleng's avatar Håvard Daleng
Browse files

Created class Vector2D.

parent dd6651dc
No related branches found
No related tags found
1 merge request!1Merge master and main
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
......
<?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
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment