[algogeeks] Re: Chord Intersection

2006-05-02 Thread wade
W Karas wrote: wade wrote: The algorithm is based on the recursive reduction: intersections = intersections with chord with min(end - start) + remaining intersections It doesn't matter if the chord with min(end - start) is the shortest chord or not. I missed that.

[algogeeks] Re: Chord Intersection

2006-05-01 Thread W Karas
After more careful consideration, the only solution I can see is fairly complex. It is based on using an AVL-balanced binary search tree. In each node of the AVL tree, a count is kept of the total number of nodes in the subtree that the node is the root of. I think it is the case that the

[algogeeks] Re: Chord Intersection

2006-05-01 Thread wade
W Karas wrote: After more careful consideration, the only solution I can see is fairly complex. It is based on using an AVL-balanced binary search tree. I think you are being a bit more complex than you need to be. Also, you have a minor error in the details. Your basic idea is: A chord

[algogeeks] Re: Chord Intersection

2006-05-01 Thread W Karas
wade wrote: W Karas wrote: After more careful consideration, the only solution I can see is fairly complex. It is based on using an AVL-balanced binary search tree. I think you are being a bit more complex than you need to be. Also, you have a minor error in the details. Your basic

[algogeeks] Re: Chord Intersection

2006-05-01 Thread W Karas
wade wrote: W Karas wrote: After more careful consideration, the only solution I can see is fairly complex. It is based on using an AVL-balanced binary search tree. I think you are being a bit more complex than you need to be. Also, you have a minor error in the details. Your basic

[algogeeks] Re: Chord Intersection

2006-04-28 Thread W Karas
W Karas wrote: wade wrote: wade wrote: pramod wrote: Karas: Can you please explain your code? I'll try. Sorry, I was explaining Karthik's method which seems to be correct, not Karas's code, which seems to be incorrect. Karas's method is to sort the endpoints in order of

[algogeeks] Re: Chord Intersection

2006-04-27 Thread wade
pramod wrote: Karas: Can you please explain your code? I'll try. If you walk around the circle, you'll hit chord endpoints. The first time you hit an endpoint, we'll call the chord started. The second time you hit an endpoint, we'll call the chord finished. Lets define intersect as intersect

[algogeeks] Re: Chord Intersection

2006-04-27 Thread W Karas
pramod wrote: ... Karas: Can you please explain your code? I sort the chord endpoints based the angle of the radius it terminates from some origin. For each chord, I call the endpoint that comes first in the ordering the starting endpoint, and the other one the ending endpoint. (I believe the

[algogeeks] Re: Chord Intersection

2006-04-27 Thread wade
wade wrote: pramod wrote: Karas: Can you please explain your code? I'll try. Sorry, I was explaining Karthik's method which seems to be correct, not Karas's code, which seems to be incorrect. Karas's method is to sort the endpoints in order of increasing angle and then run: for (i = 0; i

[algogeeks] Re: Chord Intersection

2006-04-27 Thread W Karas
wade wrote: wade wrote: pramod wrote: Karas: Can you please explain your code? I'll try. Sorry, I was explaining Karthik's method which seems to be correct, not Karas's code, which seems to be incorrect. Karas's method is to sort the endpoints in order of increasing angle and

[algogeeks] Re: Chord Intersection

2006-04-26 Thread Dhyanesh
@pramod Arent all the 'n' chords part of the same circle ? If they are how can they be parallel without intersecting. If they are not of the same circle then its a different problem. @Karthik The complexity is not O(n). It is O(nlg(n)), since my first step is sorting the chords. Also you are

[algogeeks] Re: Chord Intersection

2006-04-26 Thread W Karas
Dhyanesh wrote: 1 ) Radially sort the all the points of each chord (start and end both ). 2 ) Start with the first start point. Have c=1, tot=0, done[1..n]=0 3 ) Till all points are done: a ) If its a start point then tot = tot + c c = c + 1 set done for this

[algogeeks] Re: Chord Intersection

2006-04-26 Thread W Karas
Dhyanesh wrote: 1 ) Radially sort the all the points of each chord (start and end both ). 2 ) Start with the first start point. Have c=1, tot=0, done[1..n]=0 3 ) Till all points are done: a ) If its a start point then tot = tot + c c = c + 1 set done for this

[algogeeks] Re: Chord Intersection

2006-04-26 Thread pramod
Dhyanesh: I am failing to see your point. Imagine a circle with origin as the center. You can very well imagine two chords parallel to x-axis. Say one is diameter and the other is some chord little above the diameter. These two don't intersect. How can two parallel chords in a circle intersect?

[algogeeks] Re: Chord Intersection

2006-04-25 Thread pramod
I don't think this will work. Suppose we have two chords which are parallel and both on the one side of the circle. i.e., say draw a diameter parallel to X and say the chords are above this parallel to each other. In that case, your answer will be 1 but they are not intersecting at all. I think

[algogeeks] Re: Chord Intersection

2006-04-25 Thread Karthik Singaram L
Try this variation In the previous algorithm if i am correct the complexity is O(n), that itself shows that an important step is missing somewhere. well this is my guess about the algorithm. check if it works. I do not think this is exactly the standard Bentley-Ottmann Algorithm The precondition