Results 1 to 23 of 23

Thread: 3D linear Line

  1. #1
    Zaei
    Guest
    I have the endpoints to a 3D line, and I would like to be
    able to get the x and z coordinates, after setting y to 0.
    Any suggestions? If someone knows the formula for a 3d line, please post =). Thanks.

    Z.

  2. #2
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    Try the vectorial equation.

    (x,y,z) = (x1,y1,z1) + k*(u1,u2,u3) with k as a real number

    (x,y,z) is a point of the line which we do not know

    (x1,y1,z1) is a point of the line which we do know

    (u1,u2,u3) is the vector of the line, which give us its direction and which we know.

    x=x1+k*u1
    y=y1+k*u2
    z=z1+k*u3

    I could write more, but I'm at school at the moment. I hope this helps in some way. Sorry for the possible misspelling:

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    by setting y to 0, i suppose you don't mean a projection of the line in x-z plane. Do you want to preserve the length?
    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.

  4. #4
    Zaei
    Guest
    What I want to do is to transform a mouse click into 3D world space at 0.0y(the ground). It makes sense that you could just create the line, and "trace" along it until you get to 0.0y, and there are your coordinates. Thanks much, and any more help is greatly appreciated!

    Z.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    suppose the line is V1-V2, where V1 is above the surface Y=0 and V2 is below. the intersection point is positioned proportional to the absolute of Y components of V1 and V2. So |Y1|/|Y1-Y2|*(V1-V2)+V1 is the intersection point
    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.

  6. #6
    Zaei
    Guest
    Ill try that out kedaman =). You rock! Ill let you know how I make out in an hour or so.

    Z.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    hehe
    oh and btw, in case they are both above or below the surface, the ratio will be above 1 and you will find the supposed intersection (as if the line was a ray)
    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.

  8. #8
    Zaei
    Guest
    Erg. The formula you gave me didn't work. It gave me some pretty whacked out numbers (ie, i clicked in the vicinity of (0,0,0), and i got some 6 digit number back in one of my values. Earlier though, i was thinking of ways to do this, and i though of getting the line points, and then just disregarding the y values, and convert it to 2D (looking straight down) using z as a replacement for y. Then, use a line system, with the perpendicular to the line, and where they corss, SHOULD be the intersection. My only problem is that I can't figure out how to implement it. Any suggestions, comments, help? Please? =).

    Z.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    and on what values did you get whacked numbers?
    btw, if any y components is too close to z you might get inprecise coordinate or even overflows. How does your implementation look?
    I'm a bit uncertain about what you were suggesting now.
    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.

  10. #10
    Zaei
    Guest
    If you imagine the scene as a cube from above, then draw the line through that. Then squash it flat, by disregarding al of the y values. Then, draw a line that is perpendicular to the actual line (negative reciprocal slope), and where they intersect, that should be the 0.0y intersection.
    Z.

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    that doesnt sound correct to me
    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.

  12. #12
    Zaei
    Guest
    Here is the way that I implemented your solution kedaman, maybe i got it wrong:
    Code:
    vecEnd.x = abs(tVec1.y) / abs(tVec1.y - tVec2.y) * (tVec1.x - tVec2.x) + tVec1.x;
    	vecEnd.z = abs(tVec1.y) / abs(tVec1.y - tVec2.y) * (tVec1.z - tVec2.z) + tVec1.z;
    tVec1 and tVec2 hold the endpoints, vecEnd should be the world coordinate.
    Here is the result, after clicking somewhere near 0,0:
    Code:
    -	vecEnd	{...}
    	x	262036.
    	z	1.20112

    Thanks for all of your help so far =).

    Z.

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    looks correct to me, but when you say 0,0, what is the y coordinates on tvec1 and tvec2
    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.

  14. #14
    Zaei
    Guest
    tVec1.y = 131028.(dunno what comes after this dot, but its there)
    tVec2.y = -11.32

    Z.

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    that gives a ratio of 0.999913613715334, your x coordinates must be very far apart then?
    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.

  16. #16
    Zaei
    Guest
    Dont i feel dumb. typo while assigning the screen coordinates, before getting the endpoints. I assigned the screen x to the tVec1.x. After fixing that, it came out with a z of 0.4, and an x of -18.2.

    Z.

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    so you've got everything working now?
    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.

  18. #18
    Zaei
    Guest
    The values look a whole lot better to me, but they are still off a bit. The z, is VERY close, but the x is still off, by almost 20. thanks for helping me so much, and if you think of anything, please let me know =).

    Z.

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    if you give me all values at once, i'll see you get correct results
    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.

  20. #20
    Zaei
    Guest
    ok, here goes.

    Screen Pos: x = 154, y = 381
    Endpoint1: x = -11.4650, y = 9.12081, z = 0.214873
    Endpoint2: x = 0.442616, y = -10.4461, z = 4.99706
    Intersect Coordinates: x = -17.0155, z = -2.01427

    The 3D coordinates i was aiming at were -0.5, -0.5
    Thanks much.

    Z.

  21. #21
    Zaei
    Guest
    Oh, and kedaman. You are most definately the best =).

    Z.

  22. #22
    Zaei
    Guest
    Thank you kedaman =). That did the trick. You ROCK! =). Now my day will be perfect. Thanks so very much =).

    Im very proud of my avatar =). It uses my old one too =).

    Z.

    PS: THANK YOU =).

  23. #23
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    no problem =)
    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.

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