Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.
  • sx = x starting point
  • ex = x end point
  • sy = y starting point
  • ey = y max

having all the above, plus the current x, how do I calculate with a formula an y which isn't linear but that goes faster at first and slower approaching ey instead? (such as resembling gravity)

I guess I should use some sqr or some log somewhere, but I fail to see how exactly. I know this should be trivial but it looks like my basic math skills vanished, not having used them for too long, I'm sorry.

share|improve this question
    
What exactly do you want your function to do? What's it for? –  J. M. Apr 26 '11 at 12:23
    
I'll try to clarify later, thanks. –  Lohoris Apr 26 '11 at 13:05
2  
I suggest you provide a figure showing a sketch of the desired arc, the more exact the better. We then compare it with the arcs in our catalogue and can furnish a suitable formula. –  Christian Blatter Apr 26 '11 at 13:22

1 Answer 1

There are many possible answers. One cannot know what sort of answer is most suitable for your particular application without further information. I will supply one answer that more or less fits your description. In order to avoid confusion with multiplication, I will change your notation slightly, using for example $s_x$ instead of sx, $e_x$ instead of ex, and so on.

Here is a suggested formula.
$$y=e_y-(e_y-s_y)\left(\frac{e_x-x}{e_x-s_x}\right)^2$$
It is easy to check that this works. When $x=s_x$, the squared term is equal to $1$, and $y=e_y-(e_y-s_y)=s_y$. When $x=e_x$, the squared term is $0$, and $y=e_y$. The fact that I squared ensures that the approach to $e_y$ is rapid at the beginning and slow when $y$ is close to $e_y$. I used the square function as a reaction to your mention of gravity. One can adjust the rate of approach by changing the exponent from $2$ to something else. For a more rapid approach at the beginning, use, for example, $4$ instead of $2$. You can use non-integer exponents, like $1.6$ or $2.7$ instead of $2$ to adjust things so that they fit your application reasonably.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.