Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Beschreiben Sie hier die Klasse TwoDimVector.
- *
- * @author (Ihr Name)
- * @version (eine Versionsnummer oder ein Datum)
- */
- public class TwoDimVector extends ATwoDimVector
- {
- //Attribute
- public TwoDimVector(double x, double y) {
- super(x, y);
- }
- //Methoden
- /**
- * Return the x-coordinate of the vector
- * @return x-coordinate of the vector as int-value, obtained by rounding
- * the internal double representation to the closest int (using Math.round)
- */
- public int getX(){
- return (int)Math.round(x);
- }
- /**
- * Return the y-coordinate of the vector
- * @return y-coordinate of the vector as int-value, obtained by rounding
- * the internal double representation to the closest int (using Math.round)
- */
- public int getY(){
- return (int)Math.round(y);
- }
- /**
- * Vector addition
- * @param v Other vector, so that the vector sum of this and v shall be calculated
- * @return New vector z that is the sum of this and v. If this has coordinates (x,y)
- * and v has coordinates (w,z), then z has coordinates (x+w,y+z).
- */
- public ATwoDimVector add(ATwoDimVector v){
- return new TwoDimVector(this.x + v.x, (this.y + v.y));
- }
- public ATwoDimVector sub(ATwoDimVector v){
- return new TwoDimVector(this.x - v.x, (this.y - v.x));
- }
- /**
- * Return the scalar product of this multiplied by a factor
- * @param factor The factor to be applied by the scalar product
- * @return If this has coordinates (x,y), then a new vector with
- * coordinates (factor*x,factor*y) is returned.
- */
- public ATwoDimVector scalarProduct(double factor){
- return new TwoDimVector(factor * x, factor * y);
- }
- /**
- * Return the result of the inner product of this and v
- * @param v Other vector, so that the inner product <this,v> shall
- * be calculated.
- * @return The value of <this, v>. If this has coordinates (x,y) and
- * v has coordinates (w,z), then <this,v> = x*w + y*z.
- */
- public double innerProduct(ATwoDimVector v){
- return ((this.x * v.x) + (this.y * y));
- }
- /**
- * Return the squared length of this
- * @return Squared length of this. If this has coordinates (x,y),
- * then the squared length is x*x + y*y
- */
- public double squaredLength(){
- return ((this.x * this.x) + (this.y * this.y));
- }
- /**
- * Output the internal coordinated representation.
- * @return String in format (ix,iy), where ix is the rounded int-value
- * of the x-ccordinate, and iy the rounded int-value of the y-coordinate.
- * (use Math.round)
- */
- public String toString(){
- return "(" + Math.round(x) + ", " + Math.round(y) + ")";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement