2 * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.geometry;
13 * Used to represent point in a 3D space, vector or speed.
16 public class Point3D extends Point2D implements Cloneable {
18 public static final Point3D ZERO = new Point3D();
24 public Point3D(final double x, final double y, final double z) {
30 public Point3D(final float x, final float y, final float z) {
36 public Point3D(final int x, final int y, final int z) {
42 public Point3D(final Point3D parentPoint) {
48 public Point3D add(final Point3D direction) {
55 public Point3D clone() {
56 return new Point3D(this);
59 public Point3D clone(final Point3D source) {
66 public Point3D computeMiddlePoint(final Point3D p1, final Point3D p2) {
67 x = (p1.x + p2.x) / 2d;
68 y = (p1.y + p2.y) / 2d;
69 z = (p1.z + p2.z) / 2d;
73 public double getAngleXZ(final Point3D anotherPoint) {
74 return Math.atan2(x - anotherPoint.x, z - anotherPoint.z);
77 public double getAngleYZ(final Point3D anotherPoint) {
78 return Math.atan2(y - anotherPoint.y, z - anotherPoint.z);
82 * Compute distance to another point.
84 public double getDistanceTo(final Point3D anotherPoint) {
85 final double xDelta = x - anotherPoint.x;
86 final double yDelta = y - anotherPoint.y;
87 final double zDelta = z - anotherPoint.z;
90 .sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
94 public Point3D invert() {
101 public void rotate(final Point3D center, final double angleXZ,
102 final double angleYZ) {
103 final double s1 = Math.sin(angleXZ);
104 final double c1 = Math.cos(angleXZ);
106 final double s2 = Math.sin(angleYZ);
107 final double c2 = Math.cos(angleYZ);
113 final double y1 = (z * s2) + (y * c2);
114 final double z1 = (z * c2) - (y * s2);
116 final double x1 = (z1 * s1) + (x * c1);
117 final double z2 = (z1 * c1) - (x * s1);
125 public void roundToInteger() {
131 public Point3D scaleDown(final double factor) {
138 public Point3D scaleUp(final double factor) {
145 public void setValues(final double x, final double y, final double z) {
151 public Point3D subtract(final Point3D direction) {
152 super.subtract(direction);
158 public String toString() {
159 return "x:" + x + " y:" + y + " z:" + z;
162 public Point3D translateX(final double xIncrement) {
167 public Point3D translateY(final double yIncrement) {
172 public Point3D translateZ(final double zIncrement) {
177 public boolean withinDrawingLimits() {
182 // if ((z > 0) && (x > -1000) && (y > -1000) && (x < 2000) && (y <
190 public Point3D zero() {