Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Erm Sag physics?

  1. Jul 15, 2007 #1
    Erm... "Sag" physics?


    I'm trying to program a little 2D game to test some physics out.

    What I want is a ground formed from a set of co-ordinates, with lines joining point to point to make the ground. Each point is separated 5 pixels apart.

    Code (Text):
    Now, when the player object sits upon this line, I want the line to sag down. Like a cushion. I want it to compress inwards.

    Code (Text):
    ____________             _____________
                ''.       -''
    ... for example. Where the player is at the bottom of the ditch.

    Is there an article (or maybe you wouldn't mind doing it) that could help me with being able to calculate the position of all the points of the ground to give the illusion that the ground is bending beneath the player?

    Oh, it'd be really nice if you put it in high school/secondary school terms. I'm not too familiar with extensive Physics and Mathematics vocabulary.

    Any idea?
    Thanks a bunch.
  2. jcsd
  3. Jul 15, 2007 #2

    Claude Bile

    User Avatar
    Science Advisor

    The function you want is a hyperbolic cosine function or cosh function. This function will describe the path of a string or a chain suspended by two points. The cosh function is related to exponential functions as follows;

    cosh(x) = (e^(x) + e^(-x))/2

    So if you use a function to describe the height of the ground as a function of position, you want a function that is constant everywhere except for the "sag region". The sag region will take the form of the cosh function defined above.

    The cosh function in its most general form looks like this;

    A.cosh(Bx + C) + D

    There are 4 parameters that define the position and "severity" of the sagging.

    A - Defines how deep the sagging is for a constant sag region.
    B - Defines the "concavity" of the sagging. In other words, it defines, for a given sag depth, the width of the sag region. (If you like, heavier objects will result in a more concave sag).
    C - Defines the horizontal position of the sag.
    D - Defines the vertical position of the sag. Will also determine sag depth, but will also increase the size of the sag region.

    I recommend experimenting with these parameters to get a feel for the effect each has on function shape.

    For a 2D sag effect, the ground height will simply be the product of two cosh functions, one dependent on the X coordinate, and the other on the Y coordinate.

    That's about all I can muster at a pinch, let me know how you go.

    Last edited: Jul 15, 2007
  4. Jul 16, 2007 #3
    Ok, so I've tried using the following formula:


    The line that I am testing with is 100 points across, each one seperated by 5 pixels. Therefore the sagging's center is at the 50th point. num is equal to the distance from this center (so that the curve is reversed on the other side).

    However, using this, I get a curve that looks like this:


    It looks like it's going in the right direction, however, it also needs to flatten out near the center, so that it doesn't make a point.

    Any idea how to do this?
  5. Jul 16, 2007 #4


    User Avatar
    Science Advisor
    Homework Helper

    If the sag is due to a point mass (one that has no size ) or a weight hanging down from the horizontal wire then it will come to a point.
    If you are putting an object with a know width then you just start the calculation from each side of the object. So you would use the above formula but then set the middle (say 10 points) to the value at point 45 or 55
  6. Jul 16, 2007 #5
    Aha. Good point.

    Ok, so now how do I specify the width of the sagging area? I need to be able to say, for example, that the sag should start dipping down at variable w points away from the center. Where should this go in the formula?
  7. Jul 16, 2007 #6

    Claude Bile

    User Avatar
    Science Advisor

    You will need to define a new function, something like (For an object of width w);

    Acosh(Bx+C)+D for x < -w/2+C
    Some constant for -w/2+C < x < w/2+C
    Acosh(Bx+C)+D for x > w/2+C

    So w would be your new parameter that defines the width of the flat region in the centre of the sag.

    I should emphasize though that this is just one way to accomplish this.

  8. Jul 17, 2007 #7
    Ok, so I have a function that works quite well, however it's depth seems to be dependent on the width of the sagging area, which I don't want it to be. Is there any way I can make the function so that I simply input a depth (from the original horizontal line to the point at the bottom of the sag), a width (from the center of the sag to the point where it levels off) and maybe a severity level (how quickly it sags from the outside).

    To make it easier (hopefully) for you to understand, I'll describe my situation better.

    I have a series of 100 dots, each one represented by two co-ordinates. The first dot's x-value is represented by ground[0,0] and it's y-value by ground[0,1]. I will describe the dot itself as being simply ground[0]. The second dot is then (ground[1,0],ground[1,1]) or ground[1].

    So I've created a function called sag().

    This sag function, at the moment, takes simply a width argument and a position argument. Width being from the edge of the sag to the center, and position being the number of the dot that will act as the center of the sag. For example, I could give 49 as the position, and it will be ground[49] that acts as the center of the sag.

    So what my function does is, it creates a variable i and loops, increasing i each iteration until it reaches width. So for the loop to continue i < width must be true.

    In the first loop, i = 0, so it performs my equation on ground[position] (which will be the central point). It then increases i and performs the equation on the two points next to the center. The equation it performs is:


    I do "width-i" because the cosh function must be given a higher number as it is closer to the center so that it sags more in the middle. So, for the two points next to the center, if the width was perhaps 20, it would supply 20-1 (since i equals 1 at this point), 19. And for the next two outwards, it would be 20-2, so 18.

    The problem with this equation, however, is that I am only giving it a width. And the depth and severity seems to depend entirely on this width. Here is an image with two sags created, the only difference between them being their widths:


    So what do I change the equation to if I want to be able to supply a specific depth. The severity of the sag would be a plus, but it's not quite as important. Basically, the equation should be able to calculate all of it's values from just width, depth and severity.

    I hope you understand.
  9. Jul 17, 2007 #8

    Claude Bile

    User Avatar
    Science Advisor

    I get the basic gist of your problem, the solution is to tinker with the parameters A, B and possibly D, expressing them as a function of width, rather than a set constant.

    Other than the trial and error approach mentioned above, the other option is to change your sag function, perhaps expressing it as a convolution of a square function of width w and the cosh function. I'm not sure how computationally intensive this might be though.

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Erm Sag physics?
  1. Derivatives in physics (Replies: 29)

  2. Dimension in physics (Replies: 5)