Okay, to make this short, I have 3 java files. The first one is the main, the other two are classes I'm trying to use within my main. For some reason, when I created the other two classes in netbeans by right-clicking on the package, and creating a new class, the classes don't seem to be apart of the main project or "package." In other words, the methods I've created in my other classes, aren't linked to my main. "Point3d, translate, scale, translate, rotate,line3d are the methods giving me errors in my main. Any help would be appreciated, thanks.
first class
package ddunlap_3dcoordinates;
import java.util.*;
/**
*
* @author Aiden
*/
public class DDunlap_3dCoordinates {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int x, y, z;
x = 2;
y = 3;
z = 4;
Point3d pointA = new Point3d(x, y, z);
//Let verify our starting conditions
System.out.println("Initial Points");
System.out.println(pointA.asString());
System.out.println("");
//Translate Test
System.out.println("Translate all -1");
pointA.translate(-1, -1, -1);
System.out.println(pointA.asString());
System.out.println("");
//Scale Test
System.out.println("Scale by 2");
pointA.scale(2, 2, 2);
System.out.println(pointA.asString());
System.out.println("");
//Rotate
System.out.println("Rotate 180 with respect to x-axis");
pointA.rotate(180, "x");
System.out.println(pointA.asString());
System.out.println("Rotate 180 with respect to y-axis");
pointA.rotate(180, "y");
System.out.println(pointA.asString());
System.out.println("Rotate 180 with respect to z-axis");
pointA.rotate(180, "z");
System.out.println(pointA.asString());
System.out.println("");
//Resetting points
pointA = null;
pointA = new Point3d(x, y, z);
Point3d pointB = new Point3d(0, 0, 0);
Line3d lineAB = new Line3d(pointA, pointB);
System.out.println("Line AB created");
System.out.println("Point A: " + lineAB.getA().asString());
System.out.println("Point B: " + lineAB.getB().asString());
System.out.println("");
//Scale line points
System.out.println("Scale by 2");
lineAB.scale(2, 2, 2);
System.out.println("Point A: " + lineAB.getA().asString());
System.out.println("Point B: " + lineAB.getB().asString());
System.out.println("");
//Translate by 1,1,1
System.out.println("Translate by 1,1,1");
lineAB.translate(1, 1, 1);
System.out.println("Point A: " + lineAB.getA().asString());
System.out.println("Point B: " + lineAB.getB().asString());
System.out.println("");
//Translate by -1.-1,-1
System.out.println("Translate by -1,-1,-1");
lineAB.translate(-1, -1, -1);
System.out.println("Point A: " + lineAB.getA().asString());
System.out.println("Point B: " + lineAB.getB().asString());
System.out.println("");
//Rotate
System.out.println("Rotate 180 with respect to x-axis");
lineAB.rotate(180, "x");
System.out.println("Point A: " + lineAB.getA().asString());
System.out.println("Point B: " + lineAB.getB().asString());
System.out.println("");
System.out.println("Rotate 180 with respect to y-axis");
lineAB.rotate(180, "y");
System.out.println("Point A: " + lineAB.getA().asString());
System.out.println("Point B: " + lineAB.getB().asString());
System.out.println("");
System.out.println("Rotate 180 with respect to z-axis");
lineAB.rotate(180, "z");
System.out.println("Point A: " + lineAB.getA().asString());
System.out.println("Point B: " + lineAB.getB().asString());
System.out.println("");
System.out.println("");
}
}
second class
public class Point3d {
private double x, y, z;
public Point3d(double x, double y, double z) {
//Using this.variable will assign the value to the class.variable
//This can be avoided by renaming the arguments above
this.x = x;
this.y = y;
this.z = z;
}
//Mutator
void setX(double X) {
x = X;
}
void sety(double Y) {
y = Y;
}
void setZ(double X) {
z = X;
}
void setPoints(double X, double Y, double Z) {
x = X;
y = Y;
z = Z;
}
//Accessor
double getX() {
return x;
}
double getY() {
return y;
}
double getZ() {
return z;
}
//Scale
void scale(double xFactor, double yFactor, double zFactor){
x = x*xFactor;
y = y*yFactor;
z = z*zFactor;
}
//Translate
void translate(double xFactor, double yFactor, double zFactor){
x += xFactor;
y += yFactor;
z += zFactor;
}
//Rotate
void rotate(double theta, String axis){
//If invalid values are passed reject an notify user
if(axis.isEmpty() || theta == 0 || axis.length() != 1){
System.out.println("Error: Invalid args");
return;
}
//Math.trigs expects radians! Convert degrees to radians
theta = theta * (Math.PI/180);
//Convert axis to lower
axis = axis.toLowerCase();
//x rotation
if(axis.equals("x")){
//x = x;
y = (y * Math.cos(theta) - (z * Math.sin(theta)));
z = (y * Math.sin(theta)) + (z * Math.cos(theta));
return;
}
//y rotation
if(axis.equals("y")){
x = x * Math.cos(theta) + z * Math.sin(theta);
//y = y;
//0 minus x is -x
z = (0-x) * Math.sin(theta) + z * Math.cos(theta);
return;
}
if(axis.equals("z")){
x = x * Math.cos(theta) - y * Math.sin(theta);
y = x * Math.sin(theta) + y * Math.cos(theta);
//z = z;
}
}
//Value retrieval for debugging
String asString(){
return "X: " + x + " Y: " + y + " Z: " + z;
}
}
third class
public class Line3d {
Point3d lineA;
Point3d lineB;
Line3d(Point3d a, Point3d b) {
lineA = new Point3d(a.getX(), a.getY(), a.getZ());
lineB = new Point3d(b.getX(), b.getY(), b.getZ());
}
void setA(Point3d a) {
//Java has a garbage collector and you do not need to do this
//but setting an object to null will close all references to the object
//and allow Java GC to clean it up
lineA = null;
lineA = new Point3d(a.getX(), a.getY(), a.getZ());
}
void setB(Point3d b) {
lineB = null;
lineB = new Point3d(b.getX(), b.getY(), b.getZ());
}
//We already have an object to handle points, using the object will allow us to reuse code
Point3d getA() {
return lineA;
}
Point3d getB() {
return lineB;
}
void scale(double xFactor, double yFactor, double zFactor) {
lineA.scale(xFactor, yFactor, zFactor);
lineB.scale(xFactor, yFactor, zFactor);
}
void translate(double xFactor, double yFactor, double zFactor) {
lineA.translate(xFactor, yFactor, zFactor);
lineB.translate(xFactor, yFactor, zFactor);
}
void rotate(double degrees, String axis){
lineA.rotate(degrees, axis);
lineB.rotate(degrees, axis);
}
}