(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
06-29-24 03:53 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - Line intersection?
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
MathOnNapkins
Posts: 977/1106
Originally posted by HyperHacker
Right, but how do you tell in general? Is it always that way?


Unless you have some reason to assume that it is sine or cosine of several varied arguments, I'd not worry too much about it. if it was sin wx or cos 3x + 5 then I'd be a little more worried. Common sense says that most equations for practical usage are not going to involve sines and cosines within one another, but yeah I do understand your frustration.

And boo to Blackhole for ruining the fun.
Smallhacker
Posts: 774/832
Thanks a lot.
HyperHacker
Posts: 4209/5072
Right, but how do you tell in general? Is it always that way?
blackhole89
Posts: 325/427
(sin b) (cos a) - (cos b) (sin a).
HyperHacker
Posts: 4207/5072
This is probably the biggest problem I have when people post equations.
Originally posted by blackhole89
m=(y1 cos a + x2 sin a - x1 sin a - y2 cos a)/(sin b cos a - cos b sin a)

Now is that sin (b * cos a) or sin b * cos a or sin ((b * cos a) - cos b) or what? Is there a defined order for these operations I don't know about?
blackhole89
Posts: 324/427
For a clearer solution (which I schemed out on paper yesterday but were unable to post due to various reasons until now D

Let x1, y1 be the coordinates of the given point of line 1 and a be its slope angle.
Let x2, y2 be the coordinates of the given point of line 2 and b be its slope angle.
(They'd be alpha and beta, but I am unsure as to what encoding to use here for greek letters...)

Then...
you first retrieve a factor m:

m=(y1 cos a + x2 sin a - x1 sin a - y2 cos a)/(sin b cos a - cos b sin a).

Then you calculate the point of intersection, which may be defined as (u, v), as follows:

x2 + m cos b = u
y2 + m sin b = v

For a=b, the lines are obviously parallel, leading to (sin b cos a - cos b sin a) = 0 and thus no results.

Hope that helps...

(I didn't deep-verify it against minor calculation errors yet, but an elementary test with (0,0),45° and (1,0),90° I did yielded correct results)
MathOnNapkins
Posts: 973/1106
If you know the equations for the two lines the solution is a simple matrix calculation. In general, if you have:

ax + by = c (first line's equation)
dx + ey = f (second line's equation)

Then the point where they would hypothetically intersect would be the solution of the matrix equation:

[[a b]][x] = [c]
[[c d]][y] [f]

i.e. you multiply by the inverse of the matrix A, where A is:

[[a b]]
[[c d]]

and the vector x̄ = [x,y]t (t indicates transpose)

let [c,f]t be represented as ȳ as well.

thus producing A-1Ax̄= x̄= A-1ȳ which would yield your answer. If the matrix is singular (noninvertible) then the lines are parallel, and possibly collinear (the same exact line).

Most programming languages have libraries that allow you to deal with Matrix manipulation, even inversion, though the formula for inverting a 2x2 matrix is simple anyways. You may want to use the library just to make the code readable. The case for 3 dimensional lines and above is more complicated of course, but still pretty easy.

(btw, I didn't fully read your post at first, but slopes are not a problem when using standard form anyways, so I'd suggest you use this format. You can derive the standard form ax + by = c type equation from just an angle and a coordinate, but I won't say how b/c that would spoil the fun of figuring it out )
HyperHacker
Posts: 4197/5072
Could you post the formula? Maybe someone can spot a flaw in it.

Also, I have a formula that determines whether a line intersects a triangle in 3D space if that would help. I know that's probably basic stuff to anyone who does a lot of 3D work, but it's a pain to someone who isn't experienced in the field and didn't pay attention in Trigonometry class.
Smallhacker
Posts: 772/832
Well... Technically, this is a math problem, but there's no math forum. Also, I need this for a program, so I guess that it sort of fits here.

I need a formula for calculating the location at which two infinite lines intersects. The lines are described with a coordinate and an angle, instead of a coordinate and a slope (due to 90 degrees having an infinite slope and such stuff).

I've created a formula myself, but it doesn't work with all angles.

Does anyone have a formula that calculates the intersection of two lines that works in all cases (except when the lines are parallel)?
Acmlm's Board - I3 Archive - Programming - Line intersection?


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.012 seconds; used 357.22 kB (max 404.15 kB)