Click here to Skip to main content
15,881,757 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionKnapsack Problem Algorithm [modified] Pin
Nikolay Nedelchev29-Jun-11 8:24
Nikolay Nedelchev29-Jun-11 8:24 
AnswerRe: Knapsack Problem Algorithm Pin
OriginalGriff30-Jun-11 9:26
mveOriginalGriff30-Jun-11 9:26 
QuestionLine Intersection Pin
musefan17-Jun-11 3:20
musefan17-Jun-11 3:20 
AnswerRe: Line Intersection Pin
dasblinkenlight17-Jun-11 5:51
dasblinkenlight17-Jun-11 5:51 
GeneralRe: Line Intersection Pin
musefan17-Jun-11 5:55
musefan17-Jun-11 5:55 
AnswerRe: Line Intersection Pin
Roger Wright17-Jun-11 20:34
professionalRoger Wright17-Jun-11 20:34 
GeneralRe: Line Intersection Pin
musefan21-Jun-11 0:12
musefan21-Jun-11 0:12 
AnswerRe: Line Intersection Pin
BobJanova20-Jun-11 23:41
BobJanova20-Jun-11 23:41 
In general, lines in 3D do not intersect. The closest thing is the line-line closest approach[^] which is too complex to explain here, but that article is good.

The Z axis is actually not important, I want an intersect point on only X and Y planes
This leads me to believe that you actually want 2D line intersection. There are a number of ways to formulate that but a nice one is using the line equations:

Line 1 = (a1,b1) + k1(dx1,dy1) =>
  x1 = a1 + k1.dx1 and
  y1 = b1 + k1.dy1
Line 2 = (a2,b2) + k2(dx2,dy2) =>
  x2 = a2 + k2.dx2 and
  y2 = b2 + k2.dy2

Target: L1 = L2 =>
a1 + k1.dx1 = a2 + k2.dx2
b1 + k1.dy1 = b2 + k2.dy2

There are only four unknowns (k1 and k2, and the meeting point (x1,x2)). The bottom two equations eliminate the coordinates leaving two equations and two unknowns. Now eliminate k2 (k2 = (k1.dy1 + b1 - b2)/dy2):
  a1 + k1.dx1 = a2 + (dx2/dy2)(k1.dy1 + b1 - b2)
  k1(dx1 - [dx2.dy1/dy2]) = a2 + (dx2/dy2)(b1 - b2)
  k1 = [a2 + (dx2/dy2)(b1 - b2)] / (dx1 - [dx2.dy1/dy2])
Looks complex, but all those quantities are known at the start, so you can calculate k1 (unless dy2 is 0, in which case special case it, or the whole right hand side is 0, in which case the lines are parallel and there is no intersection).

Then you can use the k1 to calculate k2 from either of the last two equations, and then use k1 and k2 to find the intersection point. Note that if k1 or k2 is < 0 the intersection is 'before' the 'beginning' of the respective line; you may want to count such cases as failures, depending on the problem (and similarly for k > 1).

(NB I didn't check that maths, there may be a mistake, but the principle is sound.)
GeneralRe: Line Intersection Pin
musefan21-Jun-11 0:08
musefan21-Jun-11 0:08 
QuestionPattern Cracking Question Pin
YSLGuru16-Jun-11 12:57
YSLGuru16-Jun-11 12:57 
AnswerRe: Pattern Cracking Question Pin
Moreno Airoldi17-Jun-11 22:52
Moreno Airoldi17-Jun-11 22:52 
AnswerRe: Pattern Cracking Question Pin
dasblinkenlight20-Jun-11 9:36
dasblinkenlight20-Jun-11 9:36 
AnswerRe: Pattern Cracking Question Pin
musefan21-Jun-11 0:34
musefan21-Jun-11 0:34 
GeneralRe: Pattern Cracking Question Pin
YSLGuru21-Jun-11 10:41
YSLGuru21-Jun-11 10:41 
GeneralRe: Pattern Cracking Question Pin
BobJanova22-Jun-11 0:33
BobJanova22-Jun-11 0:33 
GeneralRe: Pattern Cracking Question Pin
musefan22-Jun-11 3:34
musefan22-Jun-11 3:34 
GeneralRe: Pattern Cracking Question Pin
BobJanova22-Jun-11 4:34
BobJanova22-Jun-11 4:34 
Questionmerge k AVL trees complexity Pin
Hesham Yassin16-Jun-11 0:14
Hesham Yassin16-Jun-11 0:14 
AnswerRe: merge k AVL trees complexity Pin
Alan Balkany16-Jun-11 5:13
Alan Balkany16-Jun-11 5:13 
GeneralRe: merge k AVL trees complexity Pin
dasblinkenlight17-Jun-11 10:10
dasblinkenlight17-Jun-11 10:10 
AnswerRe: merge k AVL trees complexity Pin
dasblinkenlight17-Jun-11 10:08
dasblinkenlight17-Jun-11 10:08 
GeneralRe: merge k AVL trees complexity Pin
Hesham Yassin17-Jun-11 10:49
Hesham Yassin17-Jun-11 10:49 
QuestionEye-like Algorithm Pin
JustWorking14-Jun-11 2:46
JustWorking14-Jun-11 2:46 
AnswerRe: Eye-like Algorithm Pin
phil.o14-Jun-11 3:39
professionalphil.o14-Jun-11 3:39 
GeneralRe: Eye-like Algorithm Pin
JustWorking14-Jun-11 4:07
JustWorking14-Jun-11 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.