Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
hyperPad

hyperPad Forum

  1. Home
  2. Help and Support
  3. Get Velocity -> Convert to a Direction

Get Velocity -> Convert to a Direction

Scheduled Pinned Locked Moved Help and Support
10 Posts 3 Posters 656 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deeeds
    wrote on last edited by
    #1

    I suck at math.

    And mathematics, too.

    How do I convert a Velocity into a direction?

    Jack de WildeJ 1 Reply Last reply
    0
    • D Deeeds

      I suck at math.

      And mathematics, too.

      How do I convert a Velocity into a direction?

      Jack de WildeJ Offline
      Jack de WildeJ Offline
      Jack de Wilde
      wrote on last edited by
      #2

      @Deeeds if you just want a formula, there's this one:

      2Atan(x/(Sqrt(x^2+y^2)+y))
      

      It's based on the tangent half angle identities, but I don't remember exactly how it works. It incorrectly returns 0 rather than +/-180 for y<=0 when x=0 (divide by zero), so you'd have to use ifs to account for that if that's a problem.

      Here it is in behaviour form without a check for 180°:

      0_1511786516225_IMG_0525.PNG

      Aidan_FireA D 2 Replies Last reply
      1
      • Jack de WildeJ Jack de Wilde

        @Deeeds if you just want a formula, there's this one:

        2Atan(x/(Sqrt(x^2+y^2)+y))
        

        It's based on the tangent half angle identities, but I don't remember exactly how it works. It incorrectly returns 0 rather than +/-180 for y<=0 when x=0 (divide by zero), so you'd have to use ifs to account for that if that's a problem.

        Here it is in behaviour form without a check for 180°:

        0_1511786516225_IMG_0525.PNG

        Aidan_FireA Offline
        Aidan_FireA Offline
        Aidan_Fire
        wrote on last edited by
        #3

        @Jack8680 Wouldn’t it be easier to just use angle = arctan(y ÷ x) with conditionals?

        Jack de WildeJ D 2 Replies Last reply
        1
        • Aidan_FireA Aidan_Fire

          @Jack8680 Wouldn’t it be easier to just use angle = arctan(y ÷ x) with conditionals?

          Jack de WildeJ Offline
          Jack de WildeJ Offline
          Jack de Wilde
          wrote on last edited by
          #4

          @Aidan-Oxley yes. I don't remember why I use such a complicated formula, it still has a conditional anyway.

          1 Reply Last reply
          0
          • Jack de WildeJ Jack de Wilde

            @Deeeds if you just want a formula, there's this one:

            2Atan(x/(Sqrt(x^2+y^2)+y))
            

            It's based on the tangent half angle identities, but I don't remember exactly how it works. It incorrectly returns 0 rather than +/-180 for y<=0 when x=0 (divide by zero), so you'd have to use ifs to account for that if that's a problem.

            Here it is in behaviour form without a check for 180°:

            0_1511786516225_IMG_0525.PNG

            D Offline
            D Offline
            Deeeds
            wrote on last edited by
            #5

            @Jack8680 This is amazing.

            Floored. THANK YOU!!!

            I want my MTV.

            1 Reply Last reply
            0
            • Aidan_FireA Aidan_Fire

              @Jack8680 Wouldn’t it be easier to just use angle = arctan(y ÷ x) with conditionals?

              D Offline
              D Offline
              Deeeds
              wrote on last edited by
              #6

              @Aidan-Oxley This gives very funky results. I have tried adding 90 to the result, but this only works for an initial call. Live updating after are inverted causing the object to rotate in the opposite direction to the velocity direction changes.

              Aidan_FireA 1 Reply Last reply
              0
              • D Deeeds

                @Aidan-Oxley This gives very funky results. I have tried adding 90 to the result, but this only works for an initial call. Live updating after are inverted causing the object to rotate in the opposite direction to the velocity direction changes.

                Aidan_FireA Offline
                Aidan_FireA Offline
                Aidan_Fire
                wrote on last edited by
                #7

                @Deeeds My formula needs conditionals, Jack’s does not. I think conditionals are more efficient in power requirement than square roots. The conditionals you’d need are If x > 0, x < 0, x = 0 (and for the x = 0 case you’d need 2 more for if y is negative or positive). Depending on how your project works, the x=0 case could be extremely rare and possibly could be ignored depending on what you’re doing with the angle. I’ll send a screenshot showing exactly what I mean.

                1 Reply Last reply
                0
                • Aidan_FireA Offline
                  Aidan_FireA Offline
                  Aidan_Fire
                  wrote on last edited by
                  #8

                  0_1511836143529_8DBE22E8-A890-4214-AA0E-A5B331CCF415.jpeg
                  I have no idea which is more efficient in processing power, but this way is definitely less straight forward than just using a formula. I’d say just stick with what you have now, it’s probably not much different.

                  D 1 Reply Last reply
                  1
                  • Aidan_FireA Aidan_Fire

                    0_1511836143529_8DBE22E8-A890-4214-AA0E-A5B331CCF415.jpeg
                    I have no idea which is more efficient in processing power, but this way is definitely less straight forward than just using a formula. I’d say just stick with what you have now, it’s probably not much different.

                    D Offline
                    D Offline
                    Deeeds
                    wrote on last edited by
                    #9

                    @Aidan-Oxley Imagine throwing a ball into the air, at an angle, and ball being smart enough to look in the direction its travelling, as that changes through the arc of its flight. Then continue doing the same when it bounces, hits a wall and reverses, or does anything a ball might do.

                    That's what I'm trying to do.

                    But it doesn't seem to work with any of these. Sometimes it reverses (starts fine then looks the other way as the direction changes) sometimes it's doing stuff I can't explain, other times it's off by 90 degrees at start, but correcting this has weird effects, and doesn't last.

                    Aidan_FireA 1 Reply Last reply
                    0
                    • D Deeeds

                      @Aidan-Oxley Imagine throwing a ball into the air, at an angle, and ball being smart enough to look in the direction its travelling, as that changes through the arc of its flight. Then continue doing the same when it bounces, hits a wall and reverses, or does anything a ball might do.

                      That's what I'm trying to do.

                      But it doesn't seem to work with any of these. Sometimes it reverses (starts fine then looks the other way as the direction changes) sometimes it's doing stuff I can't explain, other times it's off by 90 degrees at start, but correcting this has weird effects, and doesn't last.

                      Aidan_FireA Offline
                      Aidan_FireA Offline
                      Aidan_Fire
                      wrote on last edited by
                      #10

                      @Deeeds I haven’t tried using/testing Jacks formula, but I’m quite sure that my one (with the heap of conditionals) will work. The output might be a bit strange, but that’s because there’s no point in converting for example the angle of -30° into 330°, but the two angles are the same. If it’s still being strange with both my formula and Jack’s, I’ll make an example project of launching a ball as you said with an arrow pointing in it’s direction of travel.

                      1 Reply Last reply
                      0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Search