@@ -70,28 +70,26 @@ def __init__(self, posX=0, posY=0, direction=0, speedX=0, speedY=0, angSpeed=0):
7070 self .tackingAngleDownwind = 20 / 180 * pi
7171
7272
73- # Simulation
73+ # Simulation methods
7474 def applyCauses (self , forceX , forceY , torque , interval ):
7575 """Change speed according a force & torque given."""
76- # △v = a * t ; F = m * a
77- # △v = F / m * t
76+ # Translation: △v = a * t; F = m * a -> △v = F / m * t
77+ # Rotation: △ω = α * t; M = I * α -> △ω = M / I * t
7878 self .speedX += forceX / self .mass * interval
7979 self .speedY += forceY / self .mass * interval
80-
81- # △ω = α * t; M = I * α
82- # △ω = M / I * t
8380 self .angSpeed += torque / self .momentumInertia * interval
8481
8582 def moveInterval (self , interval ):
8683 """Change position according to sailsDirection and speed."""
87- # s = v * t
84+ # △ s = v * t; △α = ω * t
8885 self .posX += self .speedX * interval
8986 self .posY += self .speedY * interval
9087 self .direction = directionKeepInterval (self .direction + self .angSpeed * interval )
9188
9289 def runSailor (self ):
9390 """Activate the sailing algorithm to decide what the boat should do."""
9491 if not self .sailor is None :
92+ # Run sailor if sailor exists
9593 self .sailor .run (
9694 self .posX ,
9795 self .posY ,
@@ -100,26 +98,24 @@ def runSailor(self):
10098 self .direction ,
10199 self .dataHolder .apparentWindSpeed ,
102100 self .dataHolder .apparentWindAngle
103- ) # Run sailor
101+ )
104102
105- # Set boat properties
103+ # Retrieve boat properties from Sailor
106104 self .mainSailAngle = self .sailor .mainSailAngle
107105 # self.direction = self.sailor.boatDirection
108106 self .rudderAngle = self .sailor .rudderAngle
109107
110-
111- # Force & Torque calculations
112108 def resultingCauses (self , trueWindX , trueWindY ):
113109 """Add up all acting forces and return them as a tuple."""
114110 h = self .dataHolder
115111
112+ h .boatSpeed = self .boatSpeed ()
113+
116114 # calculate apparent wind angle
117115 (h .apparentWindX , h .apparentWindY ) = self .apparentWind (trueWindX , trueWindY )
118116 h .apparentWindAngle = self .apparentWindAngle (h .apparentWindX , h .apparentWindY )
119-
120117 apparentWindSpeedSq = cartToRadiusSq (h .apparentWindX , h .apparentWindY )
121118 h .apparentWindSpeed = sqrt (apparentWindSpeedSq )
122- h .boatSpeed = self .boatSpeed ()
123119
124120 # calculate flowSpeed
125121 (flowSpeedRudderX , flowSpeedRudderY ) = self .leverSpeedVector (self .rudderLever )
@@ -141,7 +137,6 @@ def resultingCauses(self, trueWindX, trueWindY):
141137 h .leewayAngle = self .calcLeewayAngle ()
142138 h .angleOfAttack = self .angleOfAttack (h .apparentWindAngle )
143139
144- # Sum up all acting forces
145140 (forceX , forceY , torque ) = (0 , 0 , 0 )
146141
147142 # Sail forces
@@ -184,15 +179,11 @@ def resultingCauses(self, trueWindX, trueWindY):
184179 (h .forceX , h .forceY , h .torque ) = (forceX , forceY , torque )
185180 return (forceX , forceY , torque )
186181
182+ # Import force and torque functions
187183 from .boat_forces import leverSpeedVector , sailDrag , sailLift , centerboardDrag , centerboardLift , rudderDrag , rudderLift , scalarToDragForce , scalarToLiftForce
188184 from .boat_torques import waterDragTorque , centerboardTorque , rudderTorque
189185
190186
191- # Speed calculations
192- def boatSpeedSq (self ):
193- """Return speed of the boat but squared."""
194- return pow (self .speedX , 2 ) + pow (self .speedY , 2 )
195-
196187 def boatSpeed (self ):
197188 """Return speed of the boat."""
198189 return sqrt (pow (self .speedX , 2 ) + pow (self .speedY , 2 ))
@@ -218,4 +209,4 @@ def angleOfAttack(self, apparentWindAngle):
218209
219210 def __repr__ (self ):
220211 heading = round (cartToArg (self .speedX , self .speedY ) * 180 / pi , 2 )
221- return "Boat @(%s|%s), v=%sm/s twds %s°" % (round (self .posX , 3 ), round (self .posY , 3 ), round (sqrt ( self .boatSpeedSq () ), 2 ), heading )
212+ return "Boat @(%s|%s), v=%sm/s twds %s°" % (round (self .posX , 3 ), round (self .posY , 3 ), round (self .boatSpeed ( ), 2 ), heading )
0 commit comments