Other need some math specialists...

Discussion in 'Android Questions' started by ilan, Jan 21, 2015.

  1. ilan

    ilan Expert Licensed User

    i would like to make jump in a radial path...

    i need to calculate the path for example my circle radius is 15% of the screenhight let say (80dip)

    and i would like to move the ball from pos x to pos y (50% of the screen widht = 160dip)
    and in 24 steps that means 180/24 = 7.5° and i need to get the left and top of the ball view

    and add this to a list and then say in a timer ball.left = list1.get(i) and ball.top = list1.get(i2)

    how do i calculate the path??

    (i need the x/y of the yellow points)

    balljump.png
     
    Last edited: Jan 21, 2015
  2. KMatle

    KMatle Expert Licensed User

    [​IMG]

    Start in a loop from 0 to 180 (or -90 to +90) step 7.5 (angle you want)

    Inside the loop:

    x=cos(degree)
    y=sin(degree)

    I didn't test it but it should work that way. Play with it.
     
    Erel and ilan like this.
  3. derez

    derez Expert Licensed User

    Code:
    dim a as float
    For i = 0 To 24
        a = i * 
    7.5
        x = cx - R * 
    CosD(a) - ball.width/2
        y = cy - R * 
    SinD(a) - ball.height/2
        list1.add(x)
        list2.add(y)
    Next
    cx , cy - the center of circle, R - the radius.
     
    KMatle and ilan like this.
  4. ilan

    ilan Expert Licensed User

    thanx i solved it like this



    Code:
    filljumplist(25%x24"left"'fill jumping lists jump to left
    filljumplist(25%x24"right"'fill jumping lists jump to right

    Sub filljumplist(radius As Int, steps As Double, direction As String)
    jumprcalc.Clear

    Dim jx As Float
    Dim jy As Float
    Dim angle As Float = 180/steps
    jumpingdir = direction
    jumpint = 
    0

    For i = 0 To 24
        
    If direction = "right" Then
            jx = radius - (radius * 
    CosD(angle*i))
        
    Else If direction = "left" Then
            jx = radius + (radius * 
    CosD(angle*i))
        
    End If
    jy = radius * 
    SinD(angle*i)
    jumprcalc.Add(jx & 
    "|" & jy)
    'Log(jx & "|" & jy)
    Next

    End Sub
     
    Last edited: Jan 21, 2015
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice