Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Keep in mind I'm still working on this and adding things to it.
- public class CJRVector2D
- {
- private CJRPoint2D xy;
- // Default constructor
- public CJRVector2D() { this.Set(0,0); }
- // Constructor
- public CJRVector2D( int x, int y ) { this.Set((double)x,(double)y); }
- public CJRVector2D( double x, double y ) { this.Set(x,y); }
- public CJRVector2D( float x, float y ) { this.Set((double)x,(double)y); }
- // Accessor Methods
- public double GetX() { return xy.X(); }
- public double GetY() { return xy.Y(); }
- // Mutator Methods
- public void SetX(double x) { xy.setX(x); }
- public void SetY(double y) { xy.setY(y); }
- public void Set(double x, double y) { this.SetX(x); this.SetY(y); }
- public void SetX(int x) { xy.setX((double)x); }
- public void SetY(int y) { xy.setY((double)y); }
- public void Set(int x, int y) { this.SetX(x); this.SetY(y); }
- public void SetX(float x) { xy.setX((double)x); }
- public void SetY(float y) { xy.setY((double)y); }
- public void Set(float x, float y) { this.SetX(x); this.SetY(y); }
- // Display Methods
- public void Display() { System.out.print("(" + this.GetX() + "," + this.GetY() + ")"); }
- public void DisplayLn() { System.out.println("(" + this.GetX() + "," + this.GetY() + ")"); }
- public void Negate() { this.Set((this.GetX() * -1),(this.GetY() * -1)); }
- public double LengthSquared() { return (this.GetX() * this.GetX() + this.GetY() * this.GetY()); }
- public double Length() { return Math.sqrt(this.GetX() * this.GetX() + this.GetY() * this.GetY()); }
- //ASMD of Vectors With Vectors
- public void Add(CJRVector2D v2)
- {
- double X = this.GetX() + v2.GetX();
- double Y = this.GetY() + v2.GetY();
- this.Set(X,Y);
- }
- public void Subtract(CJRVector2D v2)
- {
- double X = this.GetX() - v2.GetX();
- double Y = this.GetY() - v2.GetY();
- this.Set(X,Y);
- }
- public void Multiply(CJRVector2D v2)
- {
- double X = this.GetX() * v2.GetX();
- double Y = this.GetY() * v2.GetY();
- this.Set(X,Y);
- }
- public void Divide(CJRVector2D v2)
- {
- double X = this.GetX() / v2.GetX();
- double Y = this.GetY() / v2.GetY();
- this.Set(X,Y);
- }
- //Scalers Versions
- public void Add( double d )
- {
- double X = this.GetX() + d;
- double Y = this.GetY() + d;
- this.Set(X,Y);
- }
- public void Subtract( double d )
- {
- double X = this.GetX() - d;
- double Y = this.GetY() - d;
- this.Set(X,Y);
- }
- public void Multiply( double d )
- {
- double X = this.GetX() * d;
- double Y = this.GetY() * d;
- this.Set(X,Y);
- }
- public void Divide( double d )
- {
- double X = this.GetX() / d;
- double Y = this.GetY() / d;
- this.Set(X,Y);
- }
- public void Add( int d )
- {
- int X = (int)this.GetX() + d;
- int Y = (int)this.GetY() + d;
- this.Set(X,Y);
- }
- public void Subtract( int d )
- {
- int X = (int)this.GetX() - d;
- int Y = (int)this.GetY() - d;
- this.Set(X,Y);
- }
- public void Multiply( int d )
- {
- int X = (int)this.GetX() * d;
- int Y = (int)this.GetY() * d;
- this.Set(X,Y);
- }
- public void Divide( int d )
- {
- int X = (int)this.GetX() / d;
- int Y = (int)this.GetY() / d;
- this.Set(X,Y);
- }
- public void Add( float d )
- {
- float X = (float)this.GetX() + d;
- float Y = (float)this.GetY() + d;
- this.Set(X,Y);
- }
- public void Subtract( float d )
- {
- float X = (float)this.GetX() - d;
- float Y = (float)this.GetY() - d;
- this.Set(X,Y);
- }
- public void Multiply( float d )
- {
- float X = (float)this.GetX() * d;
- float Y = (float)this.GetY() * d;
- this.Set(X,Y);
- }
- public void Divide( float d )
- {
- float X = (float)this.GetX() / d;
- float Y = (float)this.GetY() / d;
- this.Set(X,Y);
- }
- public void Zero() { this.Set(0,0); System.out.println("(" + xy.X() + "," + xy.Y() + ")"); }
- public boolean Equals(CJRVector2D v2)
- {
- boolean Xx = (this.GetX() == v2.GetX());
- boolean Yy = (this.GetY() == v2.GetY());
- if(Xx && Yy)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public boolean NotEquals(CJRVector2D v2)
- {
- boolean Xx = (this.GetX() == v2.GetX());
- boolean Yy = (this.GetY() == v2.GetY());
- if(!Xx && !Yy)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public double DotProduct( CJRVector2D v2 )
- {
- double XX = (this.GetX() * v2.GetX());
- double YY = (this.GetY() * v2.GetY());
- return XX + YY;
- }
- public double CrossProduct( CJRVector2D v2 )
- {
- double XX = (this.GetX() * v2.GetX());
- double YY = (this.GetY() * v2.GetY());
- return XX - YY;
- }
- }
- //The point 2d that goes with it
- public class CJRPoint2D extends Object
- {
- private double x, y;
- public CJRPoint2D()
- {
- setX(0);
- setY(0);
- }
- //int constructor
- public CJRPoint2D(int x, int y) {
- setX(x);
- setY(y);
- }
- //float constructor
- public CJRPoint2D(float x, float y) {
- setX(x);
- setY(y);
- }
- //double constructor
- public CJRPoint2D(double x, double y) {
- setX(x);
- setY(y);
- }
- //X property
- double X() { return x; }
- public void setX(double x) { this.x = x; }
- public void setX(float x) { this.x = (double) x; }
- public void setX(int x) { this.x = (double) x; }
- //Y property
- double Y() { return y; }
- public void setY(double y) { this.y = y; }
- public void setY(float y) { this.y = (double) y; }
- public void setY(int y) { this.y = (double) y; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement