Results 1 to 4 of 4

Thread: how can i walk throw the line?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007

    how can i walk throw the line?

    see these image:

    i know calculate the AB distance using the Pythagorean theorem.
    my question is: imagine that i'm on vector A, how can i move, vector a vector, to B?
    is just:
    X = X + 1
    Y = Y + 1
    and, true, depends on direction.. what i don't know use it..
    can anyone explain these to me?
    and yes these is a 2D, i need to know, too, in 3D.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Hyperactive Member Delaney's Avatar
    Join Date
    Nov 2019
    Paris, France

    Re: how can i walk throw the line?

    vector by vector AB= AO + OB :

    AO |X=xb-xa + OB|X=0.........= AB |X =xb-xa
    .....|Y=0.............|Y=yb-ya..........|Y =yb-ya

    the coordinates of a vector are the coordinates of the last point minus the first point

    Euclidian vector
    Last edited by Delaney; Jun 20th, 2020 at 02:40 PM.

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Southern Tier NY

    Re: how can i walk throw the line?

    You wouldn't add 1 to each, unless you want to move at a 45 degree angle.
    You need the ratio of the change in values. Traditionally, I think, the ratio is given as dY/dX.

    Depending on what is desired, I don't calculate the ratio, but just calculate the delta, and then scale each delta based on a step size, or a percentage.

    In a card game I wrote, for instance, I want cards to return "home" when they are free to do so, and I want to be able to move several cards at the same time so you can have multiple cards moving across the form on a line from where they were to the home positions.

    Since the cards should "stack" in the home position in order, from Ace to King, I don't want a lower card to arrive after a higher card. If I simply moved the cards at the same speed, the closer cards would arrive earlier than cards further away, regardless of what value the card was.

    So, I move the cards the same number of steps to reach home. If the card is further away, its steps will be larger. So, when I start moving the cards in order, from low to high, the lower card will arrive before the higher card regardless of which card is closer to home at the start.

    Using your diagram,
    dx = Xb - Xa
    dy = Yb - Ya
    To move from point A to point B in 50 steps.
    stepX = dx / 50
    stepY = dy / 50
    PosX = Xa
    PosY = Ya
    For I = 1 to 49
      PosX = PosX + stepX
      PosY = PosY + stepY
      draw new position indication
    PosX = Xb  'just to ensure we end up exactly on the point, no rounding issues
    PosY = Yb
    draw at final position.
    Or you could use a percentage position to place at a specific position.
    'calculate a point 75% of the way from A to B
    PosX = Xa + .75 * dx
    PosY = Ya + .75 * dy

    There are other alternatives, but the above should be fairly understandable, I hope.

    For 3D, just add the same code for the Z axis values, i.e. calculate dz and scale it by the same amount as you scale x and Y to get a new 3d point along a straight line between the two points.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007

    Re: how can i walk throw the line?

    isn't 100% but works fine:
    'if the vector is the destiny position, change the parameter order for get the right result... i had tested
    Private Function GetInCamVector(Origin As Position3D, Destiny As Position3D) As Position3D
        Dim Steps As Double
        Steps = Math.Sqr(Math.Abs(Destiny.x - Origin.x) ^ 2 + Math.Abs(Destiny.Y - Origin.Y) ^ 2 + Math.Abs(Destiny.Z - Origin.Z) ^ 2)
        Steps = Ceiling(Steps)
        Dim increment As Position3D
        increment.x = (Destiny.x - Origin.x) / Steps
        increment.Y = (Destiny.Y - Origin.Y) / Steps
        increment.Z = (Destiny.Z - Origin.Z) / Steps
        Dim nextpoint As Position3D
        nextpoint = Origin
        Dim i As Integer
        Dim inter As Position3D
        Dim size As Size3D
        For i = 1 To Steps
            nextpoint.x = nextpoint.x + increment.x
            nextpoint.Y = nextpoint.Y + increment.Y
            nextpoint.Z = nextpoint.Z + increment.Z
            inter.x = Math.Round(nextpoint.x)
            inter.Y = Math.Round(nextpoint.Y)
            inter.Z = Math.Round(nextpoint.Z)
            If (IsOnCamera(inter, camera1.Position, camera1.size) = True) Then
                GetInCamVector = inter
                Exit For 'yes i must exit the 'for' for not get unexpected results
            End If
        Next i
    End Function
    thank you so much for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

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