2 * Sixth 3D engine. Copyright ©2012-2018, 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;
12 import static java.lang.Math.cos;
13 import static java.lang.Math.sin;
14 import static java.lang.Math.sqrt;
17 * Used to represent point in a 3D space or vector.
20 public class Point3D extends Point2D implements Cloneable {
27 public Point3D(final double x, final double y, final double z) {
33 public Point3D(final float x, final float y, final float z) {
39 public Point3D(final int x, final int y, final int z) {
45 public Point3D(final Point3D parentPoint) {
51 public Point3D add(final Point3D direction) {
58 public Point3D clone() {
59 return new Point3D(this);
62 public Point3D clone(final Point3D source) {
69 public Point3D computeMiddlePoint(final Point3D p1, final Point3D p2) {
70 x = (p1.x + p2.x) / 2d;
71 y = (p1.y + p2.y) / 2d;
72 z = (p1.z + p2.z) / 2d;
77 public boolean isZero(){
78 return (x == 0) && (y == 0) && (z == 0);
81 public double getAngleXZ(final Point3D anotherPoint) {
82 return Math.atan2(x - anotherPoint.x, z - anotherPoint.z);
85 public double getAngleYZ(final Point3D anotherPoint) {
86 return Math.atan2(y - anotherPoint.y, z - anotherPoint.z);
90 * Compute distance to another point.
92 public double getDistanceTo(final Point3D anotherPoint) {
93 final double xDelta = x - anotherPoint.x;
94 final double yDelta = y - anotherPoint.y;
95 final double zDelta = z - anotherPoint.z;
97 return sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
101 public double getVectorLength() {
102 return sqrt(((x * x) + (y * y) + (z * z)));
106 public Point3D invert() {
113 public void rotate(final Point3D center, final double angleXZ,
114 final double angleYZ) {
115 final double s1 = sin(angleXZ);
116 final double c1 = cos(angleXZ);
118 final double s2 = sin(angleYZ);
119 final double c2 = cos(angleYZ);
125 final double y1 = (z * s2) + (y * c2);
126 final double z1 = (z * c2) - (y * s2);
128 final double x1 = (z1 * s1) + (x * c1);
129 final double z2 = (z1 * c1) - (x * s1);
137 public void roundToInteger() {
143 public Point3D scaleDown(final double factor) {
150 public Point3D scaleUp(final double factor) {
157 public void setValues(final double x, final double y, final double z) {
163 public Point3D subtract(final Point3D direction) {
164 super.subtract(direction);
170 public String toString() {
171 return "x:" + x + " y:" + y + " z:" + z;
174 public Point3D translateX(final double xIncrement) {
179 public Point3D translateY(final double yIncrement) {
184 public Point3D translateZ(final double zIncrement) {
189 public boolean isVisible() {
194 // if ((z > 0) && (x > -1000) && (y > -1000) && (x < 2000) && (y <
202 public Point3D zero() {