Last change
on this file was
193,
checked in by Maciej Komosinski, 10 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
File size:
1.1 KB
|
Line | |
---|
1 | package com.framsticks.util.math; |
---|
2 | |
---|
3 | /** |
---|
4 | * The simple class which represent point in 3d space. |
---|
5 | */ |
---|
6 | public class Point3d |
---|
7 | { |
---|
8 | public final double x; |
---|
9 | public final double y; |
---|
10 | public final double z; |
---|
11 | |
---|
12 | public Point3d() { |
---|
13 | x = 0.0; |
---|
14 | y = 0.0; |
---|
15 | z = 0.0; |
---|
16 | } |
---|
17 | |
---|
18 | public Point3d(double x, double y, double z) { |
---|
19 | this.x = x; |
---|
20 | this.y = y; |
---|
21 | this.z = z; |
---|
22 | } |
---|
23 | |
---|
24 | public Point3d(Point3d p) { |
---|
25 | x = p.x; |
---|
26 | y = p.y; |
---|
27 | z = p.z; |
---|
28 | } |
---|
29 | |
---|
30 | @Override |
---|
31 | public final String toString() { |
---|
32 | return x + " " + y + " " + z; |
---|
33 | } |
---|
34 | |
---|
35 | public final double get(int i) { |
---|
36 | switch (i) { |
---|
37 | case 0: return x; |
---|
38 | case 1: return y; |
---|
39 | case 2: return z; |
---|
40 | } |
---|
41 | assert false; |
---|
42 | return 0; |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | public final Point3d add(Point3d p) { |
---|
47 | return new Point3d(x + p.x, y + p.y, z + p.z); |
---|
48 | } |
---|
49 | |
---|
50 | public final Point3d sub(Point3d p) { |
---|
51 | return new Point3d(x - p.x, y - p.y, z - p.z); |
---|
52 | } |
---|
53 | |
---|
54 | public final double length() { |
---|
55 | return Math.sqrt(x * x + y * y + z * z); |
---|
56 | } |
---|
57 | |
---|
58 | public static class Builder { |
---|
59 | double[] a = new double[3]; |
---|
60 | |
---|
61 | public Point3d build() { return new Point3d(a[0], a[1], a[2]); } |
---|
62 | |
---|
63 | public final void set(int i, double v) { |
---|
64 | a[i] = v; |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.