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. :) :)
Printable View
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. :) :)
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.
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...
m =
X =
C =
:confused: :confused:
That is where all the tutorials didnt help they just gave letters :(
I do mean 2D :) :)
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....:D...and I am only one year older then you Doggy,....;)
:confused: :confused: :confused:
:cry: :cry: :cry: :cry:
I have a simple mind
???? Y is from whereQuote:
If you have 2 lines:
Y1 = 2x + 1
Y2 = -2x
???? X is from where
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...
Its the balancing thingy :lol: :lol: :lol: :lol:
i get it now i thought = was the result and was stumped :lol: :lol: :lol:
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 :confused: :confused: :confused:
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...
So in Line 1Quote:
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
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 :lol: :lol: :lol:
Why do you need lines to do collision detection. Can't you just use coordinates?
:cry: :cry: :cry:
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 :D :D
Click to place new rect for CD
Red Point = Collision
Green Point = No Collision
Bodwad, I've PM'd you a bunch of code for hit testing with polygonal regions. Much faster then API PtInRegion()
gauss elimination is effective to solve linear equation systems.. you can google on it.
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.Quote:
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 :confused: :confused: :confused:
Hehe...are you talking about 3D space again?Quote:
Originally posted by kedaman
gauss elimination is effective to solve linear equation systems.. you can google on it.
nD space ;) you can do linear algebra in hyperspace :D *telefrags note from another dimension*
nD space,.....:D....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.....:D
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 ;)
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...
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.
Yeah I like that too....but at school we have to learn them all...:(.....:D...but I am good at it tho'.....:D
yeah school sucks ;) I think most of the stuff we learn there are just rubbish..
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...
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 ;)
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)....