Results 1 to 28 of 28

Thread: Line Intersect

  1. #1

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Question Line Intersect

    How do you do Line intersect???

    I look it up but the maths confuses me

    Anyone know how to work out if two lines hit one another and where they hit one another.
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Generally, a line is represented as:

    y=mx+c

    The other line could be,

    y=nx+b

    Simply solve the equation, to get x and y, the point of intersection.

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Did you meen in 3D space or in 2D...if in 2D, then Medhak is right....if you ment in 3D, then I can give you an other solution...but I don't want to botter my self with it if you didn't wonder...

  4. #4

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    m =
    X =
    C =


    That is where all the tutorials didnt help they just gave letters

    I do mean 2D
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    If you have 2 lines:

    Y1 = 2x + 1
    Y2 = -2x


    then put them togheter

    2x + 1 = -2x

    4x = -1

    x = -(1/4)


    then put the X into one of them

    Y2(-(1/4)) = -2 * (-(1/4))

    y2(-(1/4)) = 1/2


    So the intersect is

    (-(1/4), 1/2)

    Did you get that...

    This is 8 years since I have been doing.......and I am only one year older then you Doggy,....

  6. #6

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176




    I have a simple mind

    If you have 2 lines:

    Y1 = 2x + 1
    Y2 = -2x
    ???? Y is from where
    ???? X is from where
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    If you have a line that is


    Y = 2x


    Then you can plot it into a XY coordinate system...


    Say if you say that x is 2 then y will be 4. Plot that into the coornate system, then you can say that x = -2 then y will be -4. Plot that into the coordnate system. Then you can draw the line between the two points and you have the line........do that for both of the Y functions...

  8. #8

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Its the balancing thingy

    i get it now i thought = was the result and was stumped
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  9. #9

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Ok assume i have two lines in a grid

    Line1 = 1,2 to 4,5
    Line2 = 1,4 to 5,1

    How does the go???

    With a drawing it intersects as 2,3
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    it's been a while since I've done this, so there might be an obvious error, but I think this is it:

    Line1 = 1,2 to 4,5

    x change = 3
    y change = 3

    so the multiplier is 1
    y = (3/3) x + n

    n is the value of y when x is 0, which means that it is 1 in this case

    so: y1 = x + 1


    Line2 = 1,4 to 5,1

    x change = 4
    y change = -3

    so the multiplier is 1
    y = (4/-3) x + n

    etc...

  11. #11

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Line1 = 1,2 to 4,5

    x change = 3
    y change = 3

    so the multiplier is 1
    y = (3/3) x + n

    n is the value of y when x is 0, which means that it is 1 in this case

    so: y1 = x + 1


    Line2 = 1,4 to 5,1

    x change = 4
    y change = -3

    so the multiplier is 1
    y = (4/-3) x + n
    So in Line 1

    if X = 3
    then Y = 4

    and in line 2
    if X = 4
    then Y = 5



    But how do i use that in Collision detection

    P.s I see you all slapping your foreheads in frustration. i will throw myself around the padded room for an extra 5 mins for you
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  12. #12
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Why do you need lines to do collision detection. Can't you just use coordinates?

  13. #13

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176


    How would i do that

    Detect if one coord falls into the space of the other objects 4 coords????

    Hmm its ok i have only just thought of this so i will test it
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  14. #14

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Click to place new rect for CD

    Red Point = Collision
    Green Point = No Collision
    Attached Files Attached Files
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  15. #15
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Bodwad, I've PM'd you a bunch of code for hit testing with polygonal regions. Much faster then API PtInRegion()
    I don't live here any more.

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    gauss elimination is effective to solve linear equation systems.. you can google on it.
    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.

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by BodwadUK
    Ok assume i have two lines in a grid

    Line1 = 1,2 to 4,5
    Line2 = 1,4 to 5,1

    How does the go???

    With a drawing it intersects as 2,3
    if you want to detect collision between two lines (with start and ending point) you need their equations first, and the line equation is y=kx+c where k=dy/dx where dy = difference between points in y axis and similar for dx. c=y-kx, pick either points. solve x for both equations and finally, test of the solution is between the points x and y wise for both lines.
    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
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by kedaman
    gauss elimination is effective to solve linear equation systems.. you can google on it.
    Hehe...are you talking about 3D space again?

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    nD space you can do linear algebra in hyperspace *telefrags note from another dimension*
    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
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    nD space,.........lets keep this simple....he was talking about 2D space...just put the lines equal to each other and see what X and y will be.....

  21. #21
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah thats about it, gausselimination is just a more systematic way of doing it still though its not that simple, if you have to test if two fragments of line intersect
    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.

  22. #22
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I have never used Gauss eleminasjon in 2D space....but it is a good way to do it for 3D.....most calculators are using gauss for calculating Matrices...

  23. #23
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah but matrices are not necessarily 3d.. of course you can have one million way of doing things instead of one generic way, if you think its faster, but i prefer remembering one way.
    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.

  24. #24
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Yeah I like that too....but at school we have to learn them all...........but I am good at it tho'.....

  25. #25
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah school sucks I think most of the stuff we learn there are just rubbish..
    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.

  26. #26
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Yeah it is...and that is not all....to get a degree you have to take a lot of classes that is rubbish too......I am never going to use my chemestry knowledge...but I had to take it to get my master in informatics...

  27. #27
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    thats just silly.. we have two degrees in computer science that one is more technical and includes stuff like electronics, physics and chemistry and all kind of engineering stuff.. its just waste of time imo, so I decided to switch to the other degree with more theoretical stuff, where I at least get to decide what I want to learn
    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.

  28. #28
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    We have the same classes here in Norway the 2 first years...the 1-3 next years you can choose network...or programming....but the 2 first years you have to have classes like chemestry, statestic (is that a English word) and economics, and stuff like that.....I hate it...but I am trying to get thrue it so I can be a hardcore programmer in the end.....


    PS: I got the phone number to the most beautiful girl out on town tonight......She is sooooo hot....wish me luck.....(I am still drunk)....

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