Create a data type for points in 3 dimensional space Include
Create a data type for points in 3 dimensional space. Include a constructor that takes three real coordinates x, y, and z. Include methods distance, distanceSquared for the Euclidean distance and Euclidean distance squared. JAVA ( CODE AS SIMPLE AS YOU CAN )
Solution
Here is the code for the ThreeDPoint.java class:
class ThreeDPoint
 {
     double x;
     double y;
     double z;
     //Include a constructor that takes three real coordinates x, y, and z.
     public ThreeDPoint(double x, double y, double z)
     {
        this.x = x;
        this.y = y;
        this.z = z;
     }
     //Include methods distance, distanceSquared
     public double distance(ThreeDPoint other)
     {
        return Math.sqrt(Math.pow(x-other.x, 2) + Math.pow(y-other.y, 2) + Math.pow(z-other.z, 2));
     }
     public double distanceSquared(ThreeDPoint other)
     {
        return (Math.pow(x-other.x, 2) + Math.pow(y-other.y, 2) + Math.pow(z-other.z, 2));
     }
 }

