2 * Sixth 3D engine. Copyright ©2012-2019, 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.*;
15 * Used to represent point in a 3D space or vector.
18 public class Point3D extends Point2D implements Cloneable {
25 public Point3D(final double x, final double y, final double z) {
31 public Point3D(final float x, final float y, final float z) {
37 public Point3D(final int x, final int y, final int z) {
43 public Point3D(final Point3D parentPoint) {
49 public Point3D add(final Point3D direction) {
56 public Point3D clone() {
57 return new Point3D(this);
60 public Point3D clone(final Point3D source) {
67 public Point3D computeMiddlePoint(final Point3D p1, final Point3D p2) {
68 x = (p1.x + p2.x) / 2d;
69 y = (p1.y + p2.y) / 2d;
70 z = (p1.z + p2.z) / 2d;
75 public boolean isZero() {
76 return (x == 0) && (y == 0) && (z == 0);
79 public double getAngleXZ(final Point3D anotherPoint) {
80 return Math.atan2(x - anotherPoint.x, z - anotherPoint.z);
83 public double getAngleYZ(final Point3D anotherPoint) {
84 return Math.atan2(y - anotherPoint.y, z - anotherPoint.z);
88 * Compute distance to another point.
90 public double getDistanceTo(final Point3D anotherPoint) {
91 final double xDelta = x - anotherPoint.x;
92 final double yDelta = y - anotherPoint.y;
93 final double zDelta = z - anotherPoint.z;
95 return sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
99 public double getVectorLength() {
100 return sqrt(((x * x) + (y * y) + (z * z)));
104 public Point3D invert() {
111 public void rotate(final Point3D center, final double angleXZ,
112 final double angleYZ) {
113 final double s1 = sin(angleXZ);
114 final double c1 = cos(angleXZ);
116 final double s2 = sin(angleYZ);
117 final double c2 = cos(angleYZ);
123 final double y1 = (z * s2) + (y * c2);
124 final double z1 = (z * c2) - (y * s2);
126 final double x1 = (z1 * s1) + (x * c1);
127 final double z2 = (z1 * c1) - (x * s1);
135 public void roundToInteger() {
141 public Point3D scaleDown(final double factor) {
148 public Point3D scaleUp(final double factor) {
155 public void setValues(final double x, final double y, final double z) {
161 public Point3D subtract(final Point3D direction) {
162 super.subtract(direction);
168 public String toString() {
169 return "x:" + x + " y:" + y + " z:" + z;
172 public Point3D translateX(final double xIncrement) {
177 public Point3D translateY(final double yIncrement) {
182 public Point3D translateZ(final double zIncrement) {
187 public boolean isVisible() {
192 // if ((z > 0) && (x > -1000) && (y > -1000) && (x < 2000) && (y <
200 public Point3D zero() {