-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVektor.java
32 lines (26 loc) · 825 Bytes
/
Vektor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* Vektor --
*
* Diese Klasse repraesentiert einen Punkt im Raum. Die Koordinaten werden
* mit Array von 'double'-Werten dargestellt.
*
* NB: Obwohl mit der Klasse grundsaetzlich Vektoren mit beliebig vielen
* Komponenten dargestellt werden koennen, ist diese Implementation auf
* drei Komponenten beschraenkt.
*/
public class Vektor {
public double[] v;
public Vektor () {
v = new double[3];
}
public Vektor (double x, double y, double z) {
v = new double[] { x, y, z };
}
public static Vektor add (Vektor a, Vektor b) {
return new Vektor (a.v[0] + b.v[0], a.v[1] + b.v[1],
a.v[2] + b.v[2]);
}
public static Vektor multiply (double a, Vektor b) {
return new Vektor (a * b.v[0], a * b.v[1], a * b.v[2]);
}
}