Results 1 to 13 of 13

Thread: [RESOLVED] how would i tranfer the velocity or speed of an object into a single angle reading

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Resolved [RESOLVED] how would i tranfer the velocity or speed of an object into a single angle reading

    im trying to explain this the best i can .
    this way you change the velocity to get the balls angle change ,im trying to hopyfully ,with i havent a clue ,get the angle instead.
    thanks all





    Code:
                     If Image1(i).x + Image1(i).Radius < 35 Then
                         Image1(i).vx = -Image1(i).vx
                     End If
                     If Image1(i).x + Image1(i).Radius > 981 Then
                         Image1(i).vx = -Image1(i).vx
                     End If
                     If Image1(i).y + Image1(i).Radius < 35 Then
                         Image1(i).vy = -Image1(i).vy
                     End If
                     If Image1(i).y + Image1(i).Radius > 693 Then
                         Image1(i).vy = -Image1(i).vy
                     End If

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how would i tranfer the velocity or speed of an object into a single angle readin

    Is this still the same question as in your other thread, you try to get the direction (or angle) of the moving object?
    The code shown is checking if the object is at a border and then reversing the x or y part of the velocity depending on the border that was hit.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: how would i tranfer the velocity or speed of an object into a single angle readin

    yes i think its different .
    what i would like to do is put>> Image1(i).vx = -Image1(i).vx << into >>Image1(i).Angle .
    and the same with vy.


    Code:
                        Image1(i).x = Image1(i).x + (Cos(Image1(i).Angle * Rad) * 0.4)
                        Image1(i).y = Image1(i).y + (Sin(Image1(i).Angle * Rad) * 0.4)

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how would i tranfer the velocity or speed of an object into a single angle readin

    What do you need?
    A.) Calculate the angle out of .VX and .VY?
    or
    B.) How to change the actual angle when hitting a border?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: how would i tranfer the velocity or speed of an object into a single angle readin

    A
    thanks

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how would i tranfer the velocity or speed of an object into a single angle readin

    As I said in your other thread, have a look into trigonometry.
    For all cardinal directions it would be:
    VX=0 and VY positve Direction 0° or 360° (I'm using the navigational notation)
    VX=0 and VY negative Direction 180°
    VX positive and VY=0 Direction 090°
    VX negative and VY=0 Direction 270°
    all others can be computed out of VX/VY or VY/VX which will give you the sin or cos of the angle.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: how would i tranfer the velocity or speed of an object into a single angle readin

    thanks alot im gonna put this in my notes for the future ref
    this means divided by right VX/VY ?

    on a computer screen this VX positive and VY=0 Direction 090° means 0 or 360 ?

  8. #8
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [RESOLVED] how would i tranfer the velocity or speed of an object into a single a

    I used DY positive for UP, while an increasing Y will move the objects down, my fault SORRY. So you you the turn that around.
    DX positive will move objects to the right!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] how would i tranfer the velocity or speed of an object into a single a

    hey yall i got this off the web ,but all the degrees are in the wrong places
    ive tryed changing it but there still wrong ,need alittle help
    thanks


    Code:
    Public Function GetDirection(ByVal xVelocity As Long, ByVal yVelocity As Long) As Single
    
      Dim Direction As Single
    
          If yVelocity < 0 Then
            Direction = PI + Atn(xVelocity / yVelocity)
          ElseIf yVelocity > 0 Then
            Direction = Atn(xVelocity / yVelocity)
    
            If Direction < 0 Then
                Direction = Direction + TwoPi
            End If
    
          ElseIf xVelocity <= 0 Then
            Direction = ThreePiByTwo
          Else
            Direction = PiByTwo
          End If
    
        GetDirection = Direction
    
    End Function

  10. #10
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [RESOLVED] how would i tranfer the velocity or speed of an object into a single a

    So you are using Direction in Radians!
    The calculations seem correct to me, however they are assuming positive yVelocity is UP and positive xVelocity is to the Rigth.
    When you position anything on the screen y increases DOWN and x increases RIGTH.

    Which way do you need?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  11. #11
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [RESOLVED] how would i tranfer the velocity or speed of an object into a single a

    I would use it like this:
    Code:
    Public Function GetDirection(ByVal xVelocity As Long, ByVal yVelocity As Long) As Single
      Dim Direction As Single
        If yVelocity <> 0 Then
          Direction = Atn(xVelocity / yVelocity)
          If xVelocity < 0 Then
            'Quadrant III (-/-)   
            Direction = PI + Direction
          Else
            'Quadrant IV (-/+)   
            Direction = 2*PI + Direction
          End If
        Else
          If yVelocity>0 Then
            'Quadrant I (+/+)
            'Direction=Direction
          Else
            'Quadrant II (+/-)
            Direction=PI + Direction
          End If
        End If 
      Else
        If xVelocity > 0 Then
          Direction = PI/2
        Else
          Direction = 3*PI/2
        End If
      End If
      GetDirection = Direction
    End Function
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] how would i tranfer the velocity or speed of an object into a single a

    thanks all hafter wracking my brain i got it ,i think its right now for computer screen.
    thanks again




    Code:
    Public Function GetDirection(ByVal xVelocity As Long, ByVal yVelocity As Long) As Single
      Dim Direction As Single
        If yVelocity <> 0 Then
                Direction = Atn(xVelocity / yVelocity)
                If xVelocity = 0 Then
                   If yVelocity > 0 Then
                       Direction = 3 * PI / 2
                   Else
                       Direction = PI / 2
                   End If
                ElseIf yVelocity < 0 Then
                 If xVelocity < 0 Then
                    Direction = PI - Direction
                 Else
                    Direction = PI / 2 + Direction
                 End If
                ElseIf xVelocity > 0 Then
                 If yVelocity < 0 Then
                    Direction = PI / 2 + Direction
                 Else
                    Direction = 3 * PI / 2 + Direction
                 End If
                Else
                    Direction = 3 * PI / 2 + Direction
                End If
        Else
                If xVelocity > 0 Then
                Else
                    Direction = PI + Direction
                End If
        End If
      
        
     
      GetDirection = Direction
    End Function

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] how would i tranfer the velocity or speed of an object into a single a

    hey opus and all
    when dealing with velocitis the speed of x and y ,to change the angle an object is flying in,should i change the x and y velocitis or just the angle?
    why im asking when i mess with the velocitis ,give them -1 or .1 there angles are wrong.

    thanks all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width