summaryrefslogtreecommitdiff
path: root/src/sims/dynamics/joints
diff options
context:
space:
mode:
Diffstat (limited to 'src/sims/dynamics/joints')
-rw-r--r--src/sims/dynamics/joints/DistanceJoint.scala36
-rw-r--r--src/sims/dynamics/joints/ForceJoint.scala4
-rw-r--r--src/sims/dynamics/joints/Joint.scala12
-rw-r--r--src/sims/dynamics/joints/RevoluteJoint.scala4
-rw-r--r--src/sims/dynamics/joints/SpringJoint.scala44
-rw-r--r--src/sims/dynamics/joints/test/PrismaticJoint.scala26
6 files changed, 63 insertions, 63 deletions
diff --git a/src/sims/dynamics/joints/DistanceJoint.scala b/src/sims/dynamics/joints/DistanceJoint.scala
index 2d5633f..efb49e5 100644
--- a/src/sims/dynamics/joints/DistanceJoint.scala
+++ b/src/sims/dynamics/joints/DistanceJoint.scala
@@ -8,15 +8,15 @@ package sims.dynamics.joints
import sims.geometry._
-/** DistanceJoints halten die Bindungspunkte auf ihren Bindungskoerpern bei einem konstanten Abstand.
- * @param node1 erster Koerper der Verbindung
- * @param anchor1 Bindungspunkt auf Koerper eins
- * @param node2 zweiter Koerper der Verbindung
- * @param anchor2 Bindungspunkt auf Koerper zwei*/
+/** DistanceJoints keep their connection points at a constant distance.
+ * @param node1 first associated body
+ * @param anchor1 first connection point
+ * @param node2 second associated body
+ * @param anchor2 second connection point*/
case class DistanceJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2: Vector2D) extends Joint{
def this(node1: Body, node2: Body) = this(node1, node1.pos, node2, node2.pos)
- /**Abstand der beiden Bindungspunkte bei initialisierung (der gewollte Abstand).*/
+ /**Distance between the two connection points at initialisation (the desired distance).*/
val distance = (anchor2 - anchor1).length
private val a1 = anchor1 - node1.pos
@@ -24,16 +24,16 @@ case class DistanceJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2: V
private val initRotation1 = node1.rotation
private val initRotation2 = node2.rotation
- /**Ergibt den Bindungspunkt auf Koerper eins.*/
+ /**Returns the connection point on body one (in world coordinates).*/
def connection1 = (a1 rotate (node1.rotation - initRotation1)) + node1.pos
- /**Ergibt den Bindungspunkt auf Koerper zwei.*/
+ /**Returns the connection point on body two (in world coordinates).*/
def connection2 = (a2 rotate (node2.rotation - initRotation2)) + node2.pos
- /**Relative Position der Bindungspunkte.*/
+ /**Relative position of the connection points.*/
def x = connection2 - connection1
- /**Relative Geschwindigkeit der Bindungspunkte.*/
+ /**Relative velocity of the connection points.*/
def v = node2.velocityOfPoint(connection2) - node1.velocityOfPoint(connection1)
/* x = connection2 - connection1
@@ -45,15 +45,15 @@ case class DistanceJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2: V
* 1/m = J * M^-1 * JT
* = 1/m1 * u * u + 1/m2 * u * u + 1/I1 * (r1 cross u)^2 + 1/I2 * (r2 cross u)^2*/
override def correctVelocity(h: Double) = {
- val x = this.x //relativer Abstand
- val v = this.v //relative Geschwindigkeit
- val r1 = (connection1 - node1.pos) //Abstand Punkt-Schwerpunkt, Koerper 1
- val r2 = (connection2 - node2.pos) //Abstand Punkt-Schwerpunkt, Koerper 2
- val cr1 = r1 cross x.unit //Kreuzprodukt
- val cr2 = r2 cross x.unit //Kreuzprodukt
- val Cdot = x.unit dot v //Velocity-Constraint
+ val x = this.x //relative position
+ val v = this.v //relative velocity
+ val r1 = (connection1 - node1.pos)
+ val r2 = (connection2 - node2.pos)
+ val cr1 = r1 cross x.unit
+ val cr2 = r2 cross x.unit
+ val Cdot = x.unit dot v //velocity constraint
val invMass = 1/node1.mass + 1/node1.I * cr1 * cr1 + 1/node2.mass + 1/node2.I * cr2 * cr2 //=J M^-1 JT
- val m = if (invMass == 0.0) 0.0 else 1/invMass //Test um Nulldivision zu vermeiden
+ val m = if (invMass == 0.0) 0.0 else 1/invMass //avoid division by zero
val lambda = -m * Cdot //=-JV/JM^-1JT
val impulse = x.unit * lambda //P=J lambda
node1.applyImpulse(-impulse, connection1)
diff --git a/src/sims/dynamics/joints/ForceJoint.scala b/src/sims/dynamics/joints/ForceJoint.scala
index fa17eac..1eed850 100644
--- a/src/sims/dynamics/joints/ForceJoint.scala
+++ b/src/sims/dynamics/joints/ForceJoint.scala
@@ -6,9 +6,9 @@
package sims.dynamics.joints
-/**Eine Verbindung die Kraft auf ihre Bindungskoerper ausueben kann.*/
+/**A joint which can apply a force to its anchor bodies, thus adding or removing energy to the system.*/
trait ForceJoint {
- /**Uebt eine Kraft auf die Bindungskoerper aus.*/
+ /**Applies a force on the achor bodies.*/
def applyForce(): Unit
}
diff --git a/src/sims/dynamics/joints/Joint.scala b/src/sims/dynamics/joints/Joint.scala
index 9690af2..652df97 100644
--- a/src/sims/dynamics/joints/Joint.scala
+++ b/src/sims/dynamics/joints/Joint.scala
@@ -9,19 +9,19 @@ package sims.dynamics.joints
import sims.geometry._
import sims.dynamics._
-/**Joints sind Verbindungen die die Bewegung zwischen zwei Koerpern einschraenken.
- * Ihre Implementierung wurde von Erin Catto's box2d inspiriert.*/
+/**Joints constrain the movement of two bodies.
+ * Their implementation was inspired by Erin Catto's box2d.*/
abstract class Joint extends Constraint{
- /**Erster Koerper der Verbindung.*/
+ /**First body of the joint.*/
val node1: Body
- /**Zweiter Koerper der Verbindung.*/
+ /**Second body of the joint.*/
val node2: Body
- /**Korrigiert die Geschwindigkeit der Koerper damit diese den Randbedingungen der Verbindung entsprechen.*/
+ /**Corrects the velocities of this joint's associated bodies.*/
def correctVelocity(h: Double): Unit
- /**Korrigiert die Position der Koerper damit diese den Randbedingungen der Verbindung entsprechen.*/
+ /**Corrects the positions of this joint's associated bodies.*/
def correctPosition(h: Double): Unit
} \ No newline at end of file
diff --git a/src/sims/dynamics/joints/RevoluteJoint.scala b/src/sims/dynamics/joints/RevoluteJoint.scala
index 7a7ae1c..66a4c06 100644
--- a/src/sims/dynamics/joints/RevoluteJoint.scala
+++ b/src/sims/dynamics/joints/RevoluteJoint.scala
@@ -11,7 +11,9 @@ import sims.math._
import sims.dynamics._
import Math._
-/**Ein Gelenk, dass zwei Koerper an einem Punkt verbindet. Inspiriert von JBox2D.*/
+/**A revolute joint that connects two bodies at a singe point. Inspired from JBox2D.
+ * <b>Warning:</b> there are still several bugs with revolute joints, if they are between two free
+ * bodies and not connected at their respective COMs.*/
case class RevoluteJoint(node1: Body, node2: Body, anchor: Vector2D) extends Joint{
private val a1 = anchor - node1.pos
private val a2 = anchor - node2.pos
diff --git a/src/sims/dynamics/joints/SpringJoint.scala b/src/sims/dynamics/joints/SpringJoint.scala
index 67ea57f..1267ccf 100644
--- a/src/sims/dynamics/joints/SpringJoint.scala
+++ b/src/sims/dynamics/joints/SpringJoint.scala
@@ -8,13 +8,13 @@ package sims.dynamics.joints
import sims.geometry._
-/**Eine Hooksche Feder.
- * @param node1 erster Koerper der Verbindung
- * @param anchor1 Bindungspunkt auf Koerper eins
- * @param node2 zweiter Koerper der Verbindung
- * @param anchor2 Bindungspunkt auf Koerper zwei
- * @param springConstant Federkonstante
- * @param initialLength Initiallaenge
+/**A spring obeying Hooke's law.
+ * @param node1 first associated body
+ * @param anchor1 first connection point
+ * @param node2 second associated body
+ * @param anchor2 second connection point
+ * @param springConstant spring constant
+ * @param initialLength initial length
*/
case class SpringJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2: Vector2D, springConstant: Double, initialLength: Double) extends Joint with ForceJoint{
@@ -34,25 +34,25 @@ case class SpringJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2: Vec
private val initRotation1 = node1.rotation
private val initRotation2 = node2.rotation
- /**Ergibt den Bindungspunkt auf Koerper eins.*/
+ /**Returns the connection point on body one (in world coordinates).*/
def connection1 = (a1 rotate (node1.rotation - initRotation1)) + node1.pos
- /**Ergibt den Bindungspunkt auf Koerper zwei.*/
+ /**Returns the connection point on body two (in world coordinates).*/
def connection2 = (a2 rotate (node2.rotation - initRotation2)) + node2.pos
- /**Daempfung.*/
+ /**Damping.*/
var damping = 0.0
- /**Relative Position der Bindungspunkte.*/
+ /**Relative position of the connection points.*/
def x = connection2 - connection1
- /**Relative Geschwindigkeit der Bindungspunkte.*/
+ /**Relative velocity of the connection points.*/
def v = node2.velocityOfPoint(connection2) - node1.velocityOfPoint(connection1)
- /**Ergibt die Federkraft nach dem Hookschen Gesetz.*/
+ /**Returns the spring force.*/
def force = (x.length - initialLength) * springConstant
- /**Uebt die Federkraft auf die Bindungspunkte aus.*/
+ /**Applies the spring force to the connection points.*/
def applyForce() = {
node1.applyForce(x.unit * force - (v * damping) project x, connection1)
node2.applyForce(-x.unit * force - (v * damping) project x, connection2)
@@ -61,15 +61,15 @@ case class SpringJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2: Vec
def correctVelocity(h: Double) = {
/*
- val x = this.x //relativer Abstand
- val v = this.v //relative Geschwindigkeit
- val r1 = (connection1 - node1.pos) //Abstand Punkt-Schwerpunkt, Koerper 1
- val r2 = (connection2 - node2.pos) //Abstand Punkt-Schwerpunkt, Koerper 2
- val cr1 = r1 cross x.unit //Kreuzprodukt
- val cr2 = r2 cross x.unit //Kreuzprodukt
- val Cdot = x.unit dot v //Velocity-Constraint
+ val x = this.x
+ val v = this.v
+ val r1 = (connection1 - node1.pos)
+ val r2 = (connection2 - node2.pos)
+ val cr1 = r1 cross x.unit
+ val cr2 = r2 cross x.unit
+ val Cdot = x.unit dot v
val invMass = 1/node1.mass + 1/node1.I * cr1 * cr1 + 1/node2.mass + 1/node2.I * cr2 * cr2 //=J M^-1 JT
- val m = if (invMass == 0.0) 0.0 else 1/invMass //Test um Nulldivision zu vermeiden
+ val m = if (invMass == 0.0) 0.0 else 1/invMass
val lambda = Math.min(Math.max(-this.force * h, (-m * Cdot)), this.force * h)
println (force * h, -m * Cdot)
val impulse = x.unit * lambda
diff --git a/src/sims/dynamics/joints/test/PrismaticJoint.scala b/src/sims/dynamics/joints/test/PrismaticJoint.scala
index f163261..d4b43b2 100644
--- a/src/sims/dynamics/joints/test/PrismaticJoint.scala
+++ b/src/sims/dynamics/joints/test/PrismaticJoint.scala
@@ -15,10 +15,8 @@ case class PrismaticJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2:
def connection1 = (a1 rotate (node1.rotation - initRotation1)) + node1.pos
def connection2 = (a2 rotate (node2.rotation - initRotation2)) + node2.pos
- /**Relative Position der Bindungspunkte.*/
def x = connection2 - connection1
- /**Relative Geschwindigkeit der Bindungspunkte.*/
def v = node2.velocityOfPoint(connection2) - node1.velocityOfPoint(connection1)
@@ -28,13 +26,13 @@ case class PrismaticJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2:
}
def correctLinear(h: Double) = {
- val x = this.x.unit //relativer Abstand
+ val x = this.x.unit
val n0 = x.leftNormal
- val v = this.v //relative Geschwindigkeit
- val r1 = (connection1 - node1.pos) //Abstand Punkt-Schwerpunkt, Koerper 1
- val r2 = (connection2 - node2.pos) //Abstand Punkt-Schwerpunkt, Koerper 2
- val cr1 = r1 cross n0 //Kreuzprodukt
- val cr2 = r2 cross n0 //Kreuzprodukt
+ val v = this.v
+ val r1 = (connection1 - node1.pos)
+ val r2 = (connection2 - node2.pos)
+ val cr1 = r1 cross n0
+ val cr2 = r2 cross n0
val Cdot = n0 dot v
val invMass = 1/node1.mass + 1/node1.I * cr1 * cr1 + 1/node2.mass + 1/node2.I * cr2 * cr2
val m = if (invMass == 0.0) 0.0 else 1/invMass
@@ -57,13 +55,13 @@ case class PrismaticJoint(node1: Body, anchor1: Vector2D, node2: Body, anchor2:
def correctPosition(h: Double) = {
/*
- val x = this.x.unit //relativer Abstand
+ val x = this.x.unit
val n0 = x.leftNormal
- val v = this.v //relative Geschwindigkeit
- val r1 = (connection1 - node1.pos) //Abstand Punkt-Schwerpunkt, Koerper 1
- val r2 = (connection2 - node2.pos) //Abstand Punkt-Schwerpunkt, Koerper 2
- val cr1 = r1 cross n0 //Kreuzprodukt
- val cr2 = r2 cross n0 //Kreuzprodukt
+ val v = this.v
+ val r1 = (connection1 - node1.pos)
+ val r2 = (connection2 - node2.pos)
+ val cr1 = r1 cross n0
+ val cr2 = r2 cross n0
val C = n0 dot x
val invMass = 1/node1.mass + 1/node1.I * cr1 * cr1 + 1/node2.mass + 1/node2.I * cr2 * cr2
val m = if (invMass == 0.0) 0.0 else 1/invMass