0

I use this formula to calculate the angle on an ellipse Phi = atan(y*py/x*px), where py and px are parameters of an ellipse. When the animation crosses -PI and PI, it changes its direction by PI rad.

I use RxJs and don't know how to make a swap at right time. Maybe I need to subscribe to some event?

arrows showing the orientation of the object that I get, its moving in clockwise direction

lisichka ggg
  • 563
  • 3
  • 15
  • 1
    Can you please provide some example code to help us understand what you are asking? – laptou Feb 12 '19 at 08:58
  • @laptou this code used in facebook ar, Ive made an object and this is how I assign its position this.aPos = Reactive.point( Reactive.mul( Reactive.cos(this.angle), this.rX ), Reactive.add( Reactive.mul( Reactive.sin(this.angle), this.rY ), 10 ), 0 ); – lisichka ggg Feb 12 '19 at 11:30
  • -Pi and Pi are marked in the wrong position on your image. What you marked are actually -Pi/2 and Pi/2 radians – Tamas Hegedus Feb 12 '19 at 14:28
  • @TamasHegedus Oh yeah sorry that is correct – lisichka ggg Feb 12 '19 at 15:06

1 Answers1

0

Use Math.atan2 instead of atan.

Tamas Hegedus
  • 28,755
  • 12
  • 63
  • 97
  • it is still from -PI to PI. I think the question is more about how to add/sub PI at extremal points... – lisichka ggg Feb 12 '19 at 11:33
  • @lisichkaggg -PI to PI is fine, that's a whole circle. If your arrows still show the wrong direction that means there is an error in your rendering logic. If you could provide some of your sourcecode that we can run would be great. See [MCVE](https://stackoverflow.com/help/mcve) – Tamas Hegedus Feb 12 '19 at 14:23