-1

I need to obtain the intersection of two curves. The problem I'm facing can be stated in the following way:

Given two curves C1 and C2, defined by N1 and N2 points connected by straight lines, obtain all the intersections of C1 with C2. Both curves don't intersect themselves.

I tried several approaches, but none seems to work so far. Any guess?

Bart
  • 19,692
  • 7
  • 68
  • 77
Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
  • This seems more like a math problem than a programming problem, and would therefore be off topic. if it is a programming problem, please tell us what language and post any code you have. – ewok Dec 06 '11 at 17:36
  • Also, if this is homework, please tag it as such. – ewok Dec 06 '11 at 17:36
  • @ewok algorithm questions are supported here, there are numerous examples of questions more mathematical than this. – Codie CodeMonkey Dec 06 '11 at 17:40
  • @ewok: As a Physics Student I could be tempted to say programming is just math... this is an numerical algorithm, so it can be considered a programming question. It is not homework, but to avoid more comments about it, I added the tag. – Jorge Leitao Dec 06 '11 at 17:44
  • If it is not homework, then the tag is unnecessary. I would recommend adding a note in the question saying that it is not homework. that tag may prevent some people from giving straightforward answers. – ewok Dec 06 '11 at 17:46
  • 1
    Also, I would say that programming is a subset of math, rather than being the same as math. if this is related to an algorithm that needs to be implemented in code, then it is fine, but if it is simply "what is the mathematical way to solve this problem", then I think it belongs on http://math.stackexchange.com. Otherwise, why are there 2 different sites? – ewok Dec 06 '11 at 17:48
  • @ewok Ok, I agree, is a subset. My point is, math.stack is mainly for math, and I believe the question can more easily be answered by people who program and know computer algorithms than people who do math. – Jorge Leitao Dec 06 '11 at 17:54

2 Answers2

1

The easiest way is to test all pairs of segments, one from each curve. If that is too slow, try a strip tree. The paper below can be found at the author's web site.

Ballard, D. H. (1981), Strip trees: a hierarchical representation for curves, Communications of the ACM, v.24 n.5,310-321

lhf
  • 70,581
  • 9
  • 108
  • 149
0

Since your curves are comprised of line segments, I would suggest using a spatial tree (e.g. a quadtree) to only check segments that are in proximity to each other. This will reduce the complexity of your algorithm from O(N1 N2) to O(N log N) (where N = N1 + N2), assuming that the number of very close intersections is small.

Other than that, you can find intersections in this way.

Codie CodeMonkey
  • 7,669
  • 2
  • 29
  • 45