# Simple trajectory calculating

**URL:** <https://discourse.processing.org/t/simple-trajectory-calculating/34413>\
**Category:** Coding Questions\
**Created:** [January 1, 2022, 5:06pm UTC](https://discourse.processing.org/t/simple-trajectory-calculating/34413 "2022-01-01T17:06:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Coyote35](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Coyote35](https://discourse.processing.org/u/Coyote35)\
**Post date:** [January 1, 2022, 5:06pm UTC](https://discourse.processing.org/t/simple-trajectory-calculating/34413/1 "2022-01-01T17:06:15Z")

</div>

Hi,  
I’m trying to develop a little sketch that manages the trajectory of balls that fall from the top of the canvas, as shown on this diagram.  
I want each ball thrown from the top of the canvas to have a trajectory that points to the middle of the canvas at the bottom, where the stationary player is located. (represented here by a triangle).

Could someone suggest a piece of code that would be suitable?

Many thanks in advance.

Num

 ![concept](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/58859996c8677921662425372a0100f2d78f0e06.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 1, 2022, 9:10pm UTC](https://discourse.processing.org/t/simple-trajectory-calculating/34413/2 "2022-01-01T21:10:42Z")

</div>

Lots of possibilities

Look at lerp() command in the reference using start position and target position

Another idea would be to look at atan2 and use the angle with cos and sin

---

<div class="post-metadata">

**Author:** ![Coyote35](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Coyote35](https://discourse.processing.org/u/Coyote35)\
**Post date:** [January 2, 2022, 2:55pm UTC](https://discourse.processing.org/t/simple-trajectory-calculating/34413/3 "2022-01-02T14:55:30Z")

</div>

Hi Chrisir,

Thanks for your response.

I couldn’t find a piece of code that meets my needs and that uses the lerp( ) function or other trigonometric functions. But I adapted your idea based on “lerp( )” but using the “map( )” function.

It’s not very elegant nor very precise from the point of view of the real laws of mechanics, but it’s pretty much what I was looking for… 🙂

Here’s the snippet of code : [https://jsfiddle.net/hfp0me29/2/](https://jsfiddle.net/hfp0me29/2/)

(you can click on the canvas to pick more falling particles and see that they converge pretty well toward the bottom center).

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 2, 2022, 3:29pm UTC](https://discourse.processing.org/t/simple-trajectory-calculating/34413/4 "2022-01-02T15:29:41Z")

</div>

hi

see this nice game

[Game from Japan](https://discourse.processing.org/t/game-from-japan/28639)

---

<div class="post-metadata">

**Author:** ![Coyote35](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Coyote35](https://discourse.processing.org/u/Coyote35)\
**Post date:** [January 9, 2022, 1:31pm UTC](https://discourse.processing.org/t/simple-trajectory-calculating/34413/5 "2022-01-09T13:31:11Z")

</div>

Hello everyone,

On my JsFiddle code snippet above, we can see that the farther the ball is dropped from the central axis, the less its fall converges towards the center.

If someone could suggest a small improvement to correct this drawback, I would be interested!

Thanks a lot in advance!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 12, 2022, 10:40pm UTC](https://discourse.processing.org/t/simple-trajectory-calculating/34413/6 "2022-01-12T22:40:53Z")

</div>

kill gravity and use lerp()
