Juggling motion in PowerApps #1

##Juggling challenge in PowerApps
[@that_API_guy](https://twitter.com/that_API_guy?s=09) casted who can make [juggling apps](https://twitter.com/that_API_guy/status/1052928614466027520) in PowerApps.
I have implmented such app including natural effects of gravity and air resistance.
Here, the detail of its physical modeling and implementation into PowerApps will be represented.
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr"><a href="https://twitter.com/hashtag/PowerAppsJuggleChallenge?src=hash&amp;ref_src=twsrc%5Etfw">#PowerAppsJuggleChallenge</a><br>というのがあったので作ってみました。<a href="https://t.co/vAGeYXrSZn">https://t.co/vAGeYXrSZn</a> <a href="https://t.co/8GWLFwJGOW">pic.twitter.com/8GWLFwJGOW</a></p>&mdash; ながちん (@mofumofu_dance) <a href="https://twitter.com/mofumofu_dance/status/1053134493744214016?ref_src=twsrc%5Etfw">October 19, 2018</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> 

##Simplify the motion of juggled ball
In order to implement time development of juggled ball, first need to simplify a trajectory of ball.


In my app, trajectory of ball is devided into (mainly) two equation of motions.
1. **Projectile with Air resistance and initial velocity**
2. **Simple circular motion, representing handling of ball**

<img width="400" alt="cap1.PNG" src="https://qiita-image-store.s3.amazonaws.com/0/202779/128949f9-9b53-7768-a731-7ba9dbce33de.png">


There are given analytic expression for ball trajectory and naturally include gravity and air resistance, and represent juggler's motion.

##Motion of Projectile
For the detail of physical analysis, See [Wikipedia](https://en.wikipedia.org/wiki/Projectile_motion#Trajectory_of_a_projectile_with_air_resistance).

<img width="500" alt="proj1.PNG" src="https://qiita-image-store.s3.amazonaws.com/0/202779/2e1627ba-1754-5cef-8c1d-e401650fc3d9.png">


Now, we can implement this motion into PowerApps.
First, insert circle icon and Timer control into canvas app(no need to set orientation to landscape).
Next, set X property and Y property of icon as

```Image1.X
X0+ (Velocity_x/Friction)* (1-Exp(-1*Friction * Timer1.Value/1000))
```
```Image1.Y
Y0-(Velocity_y/Friction)*(1+Gravity/(Friction*Velocity_y)) * (1-Exp(-1*Friction * Timer1.Value/1000)) + Gravity * Timer1.Value/1000/Friction
```

**Note** that minus sign prior to *(Velocity_y/Friction)* is due to special coordinate system (*i.e.,* Y value becomes larger as it goes bottom of display).

Here, some global/context variables *{X0, Y0, Velocity_x, Velocity_y, Friction, Gravity}* are given by some text input controlls or directly set in OnVisible action (They are BASICALLY arbitrary parameter).

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">This is simulation for the effect of air resistance in <a href="https://twitter.com/hashtag/PowerApps?src=hash&amp;ref_src=twsrc%5Etfw">#PowerApps</a> <a href="https://t.co/EBDHT8SKWa">pic.twitter.com/EBDHT8SKWa</a></p>&mdash; ながちん (@mofumofu_dance) <a href="https://twitter.com/mofumofu_dance/status/1053524851120435200?ref_src=twsrc%5Etfw">October 20, 2018</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
In this tweet, I have chosen parameters as  *{X0, Y0, Gravity} = {170, 500, 500}*

# Next Post: Explain Circular motion and restriction for parameters
https://qiita.com/h-nagao/items/64fb8ee1efbbb8f44f99