Results 1 to 11 of 11

Thread: Need help with 3d jommetry (ok, ok, GEOmetry)

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    UK
    Posts
    49
    RIGHT!

    I am embarking now on my final project in college (UK). What I am making is a robotic arm simulation that shows a robotic arm on screen and the user can give commands in a console of what to move for how long or how much, etc.

    ANYWAY, the problem comes with the graphic of the arm. It will be very simply drawn, prolly made out of a collection of lines... possibly fill in if there is time. BUT I really havn't got a clue as to how you map 3d coords onto a 2d surface.
    E.g. point 1,1,0 and point 1,1,2 are the same on a 2d surface, but if you look at a 3d perspective, depending where abouts the 'camera' is situated the 2nd point will look offset from the first. What I need to know is how you can use the coords from point 1, point 2 and the camera position to map that onto a 2d surface (VDU) and make it look right. PHEW this is hard to explain. I hope someone out there gets what I am bangin' on about!
    Dave.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well here's some of my work, it's a bit old and i haven't used it for a long time so there m ight be bugs, try it out
    Code:
    Private Sub pset3d(X, Y, z)
        vinkela = Atn((z - position.z) / (Y - position.Y))
        vinkelb = Atn((X - position.X) / Sqr((Y - position.Y) ^ 2 + (z - position.z) ^ 2))
        posy = Tan(vinkela + alfa)
        posx = Tan(vinkelb + beta)
        PSet (posx, posy)
    End Sub
    Private Sub line3d(X, Y, z, x2, y2, z2)
    'Den här funktionen kom jag på den 29.9.98
        vinkela = Atn((z - position.z) / (Y - position.Y)): 'If (y - position.y) < 0 Then vinkela = vinkela + 3.1415
        vinkelb = Atn((X - position.X) / Sqr((Y - position.Y) ^ 2 + (z - position.z) ^ 2))
        If Y < position.Y Then vinkelb = vinkelb + 3.1415: ForeColor = QBColor(13) Else ForeColor = QBColor(14)
    '    If 3.1415 + beta - vinkela > 3.1415 Then Exit Sub
    '    If 3.1415 + alfa - vinkelb > 3.1415 Then Exit Sub
                    a = -3.1415 + beta - vinkelb
                        If a > 3.1415 Then a = a - Int(a / 3.1415) * 3.1415
                        If a > 1 Then Exit Sub
        
        'If -alfa - vinkela < 0 Then Exit Sub
        'If -beta - vinkelb < 0 Then Exit Sub
        posy = Tan(vinkela + alfa)
        posx = Tan(vinkelb + beta)
        vinkela = Atn((z2 - position.z) / (y2 - position.Y))
        vinkelb = Atn((x2 - position.X) / Sqr((y2 - position.Y) ^ 2 + (z2 - position.z) ^ 2))
        'If 3.1415 + beta - vinkela > 3.1415 Then Exit Sub
        'If 3.1415 + alfa - vinkelb > 3.1415 Then Exit Sub
        'If -alfa - vinkela < 0 Then Exit Sub
        'If -beta - vinkelb < 0 Then Exit Sub
        
        posy2 = Tan(vinkela + alfa)
        posx2 = Tan(vinkelb + beta)
        
        'If vinkelb - beta < 0 Then Exit Sub
        Line (posx, posy)-(posx2, posy2)
        'Print Int((vinkela) * 100)
        Print Int((vinkelb + beta) * 10)
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    UK
    Posts
    49

    Unhappy No offense.....

    Yeah.

    What?

    That confused me a LOT (especially the GERMAN comments)... the programming I can get round, I just need a formula to link the X and Y coords of a 2d surface to a point's (x, y, z) and camera's (x, y, z), so that a 3d object can be drawn on a 2d surface and look right. Damn this is difficult to explain without a diagram.... please just understand!

    Code I can't understand, unless I know the maths behind it! Teach me (urgghhh dare I say it) the MATHS behind the concept please?
    Dave.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hehe, it's not german, but swedish is a germanic language. Well the math used to project 3d objects on a 2d surface is pretty easy. But to understand it may be a hell. Well if you've past trigonometry in any math courses it could be easier. Basically you project each point on a plane placed in front of the camera, and you need to do some 3d-trig to calculate the position.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    UK
    Posts
    49

    What about a standard formula?

    Well isnt there a standard formula that is like

    x2 = (k*x3*z)*(k*xc*zc)
    y2 = (k*y3*z)*(k*yc*zc)


    where:

    x2 and y2 are the 2d point's coords
    x3 and y3 are the 3d point's coords
    z is the z coord of the 3d point

    xc and yc are the 3d camera's coords
    zc is the z coord of the camera position

    k is some kind of constant

    well, ok thats unlikely to be the formula, there will be trig functions in there, but something to that effect. Where a formula can use the x,y,z of point and x,y,z of camera to come up with x,y of 2d point. Please help oh great dude.
    Oh yeah, I have a deal of 2d trig experience. I am studying maths at college (UK). Erm, so far the last thing using trig I did was differentiation of trignometrical functions, if that helps give a clearer picture of how much experience I have.

    Dave.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sure:

    sX=Tan(alfa+tan-1((z-z0)/(Y-Y0))
    sY=Tan(beta+tan-1((x-x0)/sqr((Y-Y0)^2+(z-z0)^2))

    sX=screenx
    alfa=camera angle
    x,y,z=object position
    x0,y0,z0=camera position
    alfa, camera horizontal angle
    beta, camera vetical angle

    If you wan't gamma angle involved, i cannot help, i tried myself but i didn't get it work.
    If youre going trough differention now, i think you've gone trough 3d vectors, or, is it the other way round? I'm not sure since I have been off school for a year.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    UK
    Posts
    49

    WOW, Thats great

    Just one question about it:
    What do you mean by vertical camera angle and horizontal camera angle? - This ones gonna be hard to explain isnt it.
    Do you mean
    ...................
    .......\..........|
    ..........\.......|
    .............\...v|
    ..............h.\|
    ------------------|

    This is meant to look like a 3d graph
    The diagnal is going into the distance

    where
    v = vertical angle
    h = horizontal angle

    Dave.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    Well, i could draw a graph, but not here, i would need to draw a image.

    Instead i could say that if you were the camera, vertical angle is when you look up and down, horizontal angle is when you look left and right
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    UK
    Posts
    49

    RIght I get it, just one more question... I hope!

    tan-1((x-x0etcetc........))

    by that do you mean the inverse function of tan or the tan of (-1*((x-x0etc.........)) )
    Dave.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yes, arcus tangens
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I bought a VERY good book on 3D graphics in C++, and it explains it all very well. Basically:

    1: Translate by <-camera.x, -camera.y, -camera.z>
    2: Rotate into the new viewing system
    3: Apply the perspective transformation of choice.

    I think that's about it for simple things. Shading and Z-buffering are different, but still understandable. Email me if you want some stuff about it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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