Skip to main content

More strange behavior

It happened again. If you don't know, I'm working on a simulation of a water bug (it looks more like a round pea than a bug) that lives in water but needs to surface to breathe oxygen.

I have mentioned weird behavior before that I won't go into here. I realize it must be explained by the interaction of a number of different behaviors, which, because of the growing complexity, makes it hard to predict exactly how the program will behave.

In order to "breathe", the water pea simply has to surface periodically. The code simply says that when it's time to breathe, then surface. This sounds simple enough, but today during testing, one of the water peas simply drowned. It never even made an attempt to swim to the surface.

That may not sound so unusual, but it has happened exactly once. It should never happen. It never has happened before or since, and I can't reproduce it. So, there's that. I guess it shouldn't be so surprising; as I've said, this isn't due to a bug in the code, but in the complex interactions of the different behaviors acting together simultaneously.

There is something exciting about seeing one-off behavior like this that neither I, nor anyone else, may ever see again.

Comments

Popular posts from this blog

Collisions with line intersections

Collisions can be determined by testing for line intersections. Imagine a line representing the ground and an object above, falling down. At time t1 , take the center point  p1  of the object. At time t2 , move the object down and take the center point p2 of the object. If the line formed by endpoints (p1, p2) intersect the ground line, a collision has occurred. On a collision, reset the object to its original position before the movement. When a collision occurs, be sure to reset the object by the same point used to determine the line intersection. In this example, I use the center point, so the object should be reset by the center point, not its actual x, y (usually top left) coordinate. It is not always the case that resetting by the x, y coordinate is sufficient. This can be seen in the following picture. It can be seen that even if the object isn't moving, but its size changes, a line intersection can occur, and resetting the object to its x, y position will...

Momentum transfer

This image shows different possible paths that result in a collision. Intuitively, we know which way the object should continue along the wall. Determining this mathematically is a bit more challenging. The object could go in one of two directions. That is, it could follow the wall one way or the other. But why should it prefer one direction over another? We need a generalized rule that applies for every wall and every angle of approach. The rule is that momentum is transferred along the path of least resistance . Least resistance is the difference between the wall angle and the angle of approach that is less than 90 degrees. This raises the issue that a line's angle is determined by its direction. This means that the end point we start with determines the angle of the line. See the line below. Is it a 45 degree line, or a 225 degree line? It depends on which point you start from. But, for a generalized rule of momentum transfer, the answer shouldn't matter. ...

Moving with Trigonometry

These are some thoughts on Trigonometry that I wanted to write down, and someone, somewhere may want to read. But probably not. If you're not into it, turn back immediately. In a top-down view on a two dimensional plane, you can face any direction and move in a forward direction by moving on the x-axis by the cosine of your rotation and moving on the y-axis by the sine of your rotation. This seems to require a physical orientation in the world, but this physical limitation is only on the surface. We can take one step back and use these abilities in more subtle ways. Imagine a side view on a plane in which you can move left and right, and jump up and fall back down to the ground. Let us first think of the left and right movement in terms of trigonometry. Facing right means 0 degrees and so we can move on x by the cosine of our rotation. Facing left is 180 degrees, and we move on x by the cosine of our rotation. Let's maintain a logical rotation factor called xf . When sta...