diff options
author | Jakob Odersky <jodersky@gmail.com> | 2015-06-29 12:32:00 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2015-06-29 12:32:00 +0200 |
commit | 01c5c700647feba596e02cb7a2e672f5301504ff (patch) | |
tree | bb0b0e1c2efde6b5362a294089fe081db0724833 /src/main/scala/sims/dynamics/Rectangle.scala | |
parent | 998e545e8e42fee597f7274e47428d35dcf29e7b (diff) | |
download | sims-01c5c700647feba596e02cb7a2e672f5301504ff.tar.gz sims-01c5c700647feba596e02cb7a2e672f5301504ff.tar.bz2 sims-01c5c700647feba596e02cb7a2e672f5301504ff.zip |
Port to scala 2.11
Diffstat (limited to 'src/main/scala/sims/dynamics/Rectangle.scala')
-rw-r--r-- | src/main/scala/sims/dynamics/Rectangle.scala | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/scala/sims/dynamics/Rectangle.scala b/src/main/scala/sims/dynamics/Rectangle.scala new file mode 100644 index 0000000..89ab4c0 --- /dev/null +++ b/src/main/scala/sims/dynamics/Rectangle.scala @@ -0,0 +1,38 @@ +/* + * Simple Mechanics Simulator (SiMS) + * copyright (c) 2009 Jakob Odersky + * made available under the MIT License +*/ + +package sims.dynamics + +import sims.geometry._ +import sims.collision._ + +/**A rectangle is a polygon. + * @param halfWidth this rectangle's half width + * @param halfHeight this rectangle's half height + * @param density density of this rectangle + */ +case class Rectangle(halfWidth: Double, + halfHeight : Double, + density: Double) extends Shape with ConvexPolygon{ + + val volume = halfWidth * halfHeight * 4 + + val I = 1.0 / 12.0 * mass * ((2 * halfWidth) * (2 * halfWidth) + (2 * halfHeight) * (2 * halfHeight)) + + /**Returns the vectors from the center to the vertices of this rectangle. + * The first vertex is the upper-right vertex at a rotation of 0. + * Vertices are ordered counter-clockwise.*/ + def halfDiags: Array[Vector2D] = Array(Vector2D(halfWidth, halfHeight), + Vector2D(-halfWidth, halfHeight), + Vector2D(-halfWidth, -halfHeight), + Vector2D(halfWidth, -halfHeight)) map (_ rotate rotation) + + /**Returns the position vectors of this rectangle's vertices. + * The first vertex is the upper-right vertex at a rotation of 0. + * Vertices are ordered counter-clockwise.*/ + def vertices = for (h <- halfDiags) yield pos + h + +}
\ No newline at end of file |