Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector2D protected[mathutil] (val x: Double, val y: Double) {
- val length: Double = math.sqrt(x * x + y * y)
- def unary_- : Vector2D = new Vector2D(-x, -y)
- def normalize: Vector2D = new Vector2D(x / length, y / length)
- /** Returns the normal vector */
- def normal: Vector2D = new Vector2D(-y, x)
- def +(that: Vector2D): Vector2D = new Vector2D(x + that.x, y + that.y)
- def -(that: Vector2D): Vector2D = new Vector2D(x - that.x, y - that.y)
- def *(scalar: Double): Vector2D = new Vector2D(x * scalar, y * scalar)
- def /(scalar: Double): Vector2D = new Vector2D(x / scalar, y / scalar)
- /** Returns the scalar product */
- def *(that: Vector2D): Double = x * that.x + y * that.y
- /** Returns the angle in degrees */
- def \/(that: Vector2D): Double =
- math.toDegrees(math.acos((this * that) / (length * that.length)))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement