Rowing-like code

I am working on a small program showing moving rowing boats. The following is a simple code example (Python 2.x):

import time class Boat: def __init__(self, pace, spm): self.pace = pace #velocity of the boat in m/s self.spm = spm #strokes per minute self.distance = 0 #distance travelled def move(self, deltaT): self.distance = self.distance + (self.pace * deltaT) boat1 = Boat(3.33, 20) while True: boat1.move(0.1) print boat1.distance time.sleep(0.1) 

As you can see, the boat has a pace and rows with the number of beats per minute. Each time the move(deltaT) method is called, it moves a certain distance according to the pace.

The aforementioned boat just travels at a constant pace, which is unrealistic. A real rowing boat accelerates at the start of a turn and then slows down after the rowing blades leave the water. There are many graphs on the Internet that show a typical rowing curve (the force shown here, the speed is similar):

Rowing stroke graph Source: highperformancerowing.net

The pace should be constant over time, but it should change during the beat.

What is the best way to change a constant speed to a curve that (at least basically) resembles a more realistic rowing move?

Note. Any ideas on how to better flag this question? Is this an algorithm problem?

+6
source share
3 answers

If your goal is to simply come up with something visually plausible and not do a full physical simulation, you can simply add a sine wave to the position.

 class Boat: def __init__(self, pace, spm, var=0.5): self.pace = pace #average velocity of the boat in m/s self.sps = spm/60.0 #strokes per second self.var = var #variation in speed from 0-1 self.totalT = 0 #total time self.distance = 0 #distance traveled def move(self, deltaT): self.totalT += deltaT self.distance = self.pace * (self.totalT + self.var * math.sin(self.totalT * self.sps * 2*math.pi) 

You need to be careful with changing var , if it gets too high, the boat can go back and destroy the illusion.

+2
source

You can convert such a curve into a polynomial equation for speed.

A description / example of how to do this can be found at:

python numpy / scipy curve

This shows how to take the x, y coordinate set (which you can get by checking your existing graph or from the actual data) and create a polynomial function.

If you use the same curve for each Boat object, you can simply copy it to your program. But you can also have a separate polynomial equation for each boat object, assuming that each rower or boat has a different profile.

+1
source

You can perform simple integration of the differential equation of motion. (This is what you are already doing to get space as a function of time, at a constant speed, x' = x + V.dt )

Suppose a simple model with constant force during a stroke and no force during sliding and drag proportional to speed.

Thus, the acceleration a = P - Dv during impact and - Dv during sliding (deceleration).

The speed is approximated using v' = v + a.dt

The space is approximated by x' = x + V.dt

If dt is small enough, this movement should look realistic. You can refine the model with a more precise law of force and better integration methods such as Runge-Kutta, but I'm not sure if it's worth it.

The following is an example of the dependence of speed and space on time using this technique. It shows velocity oscillations that quickly establish a periodic regime and quasilinear displacement with waves.

enter image description here

+1
source

Source: https://habr.com/ru/post/980541/


All Articles