AB3: BodyLinkedList working

This commit is contained in:
2022-03-31 19:50:10 +02:00
parent cf4c1ad9d0
commit f24ad9bcaf
7 changed files with 252 additions and 51 deletions

View File

@ -4,7 +4,6 @@ import codedraw.CodeDraw;
* This class represents vectors in a 3D vector space.
*/
public class Vector3 {
private double x;
private double y;
private double z;
@ -27,33 +26,21 @@ public class Vector3 {
* Returns the sum of this vector and vector 'v'.
*/
public Vector3 plus(Vector3 v) {
Vector3 result = new Vector3();
result.x = x + v.x;
result.y = y + v.y;
result.z = z + v.z;
return result;
return new Vector3(x + v.x, y + v.y, z + v.z);
}
/**
* Returns the product of this vector and 'd'.
*/
public Vector3 times(double d) {
Vector3 result = new Vector3();
result.x = x * d;
result.y = y * d;
result.z = z * d;
return result;
return new Vector3(x * d, y * d, z * d);
}
/**
* Returns the sum of this vector and -1*v.
*/
public Vector3 minus(Vector3 v) {
Vector3 result = new Vector3();
result.x = x - v.x;
result.y = y - v.y;
result.z = z - v.z;
return result;
return new Vector3(x - v.x, y - v.y, z - v.z);
}
/**
@ -85,15 +72,21 @@ public class Vector3 {
z /= length;
}
public double getScreenX(CodeDraw cd) {
return cd.getWidth() * (this.x + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
}
public double getScreenY(CodeDraw cd) {
return cd.getWidth() * (this.y + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
}
/**
* Draws a filled circle with a specified radius centered at the (x,y) coordinates of this vector
* in the canvas associated with 'cd'. The z-coordinate is not used.
*/
public void drawAsFilledCircle(CodeDraw cd, double radius) {
double x = cd.getWidth() * (this.x + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
double y = cd.getWidth() * (this.y + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
radius = cd.getWidth() * radius / Simulation.SECTION_SIZE;
cd.fillCircle(x, y, Math.max(radius, 1.5));
cd.fillCircle(getScreenX(cd), getScreenY(cd), Math.max(radius, 1.5));
}
/**