Results 1 to 5 of 5

Thread: Simple maths ...

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    35
    Does anyone have the functions to determine the x,y,z function of a vector based on its angle(s) in degrees? Basically, I'm playing around with objects moving in three dimensions (think 8-ball in space) and cant find the equations to figure out what to add to x,y and z based on the direction of the object.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This is a cut from my 3d-engine
    The things here are:
    position, an userdef-type
    .x
    .y
    .z
    alfa is the vertical angle
    beta is the horisontal angle
    v is the velocity
    -------------------------
    Sub flightsim() 'Flygsimulatorn förflyttar positionen
    position.z = position.z + Sin(-alfa) * Cos(beta) * v
    position.Y = position.Y + Cos(-alfa) * Cos(beta) * v
    position.X = position.X + Sin(-beta) * v
    alfa = alfa + alfav: beta = beta + betav
    betav = betav * 0.95 'Friktion vid svängningar
    alfav = alfav * 0.95
    If alfa > 3.1415 Then alfa = alfa - 3.1415 * 2 '360 grader snurr lösning
    If alfa < -3.1415 Then alfa = alfa + 3.1415 * 2
    If beta > 3.1415 Then beta = beta - 3.1415 * 2
    If beta < -3.1415 Then beta = beta + 3.1415 * 2
    End Sub
    --------------------------
    Don't have time to modify it for your need, but try to get use of the three first lines. Don't bother to translate my swedish comments.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    35
    Thanks, but, it doesn't seem to be doing quite what I expected. How about this, on a 2d plane, the origin in the top left corner, what would one add to the x coordinate of an object if it was moving in a direction described by Q degrees, with Q=0 being the top of the plane, Q=180 being the bottom.

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    OK add R*Cos(Q/57.2958) to y and R* sin(Q/57.2958) to x

    VB likes it's angles in radians which is why the 57.2958 is there.


  5. #5
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    Your code is commented in Swedish.
    Is there a fellow Swede out there?
    Myself, I live in Kungsbacka, south of Gothenbourgh.
    Pentax
    Wilhelm Tunemyr,
    Swede in London

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

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