开发者

What is best approach for performing operations on pairs of 2d lines?

So I have 10 000 lines defined on 2d plane so that each line is presented as (A1, A2, B1, B2) (A, B points). I have an array of functions I need to perform on each pair of lines:

Angle(A,B)
    return Atan((B.y-A.y) / (B.x-A.x)) 

NearlyParallel(angle1, angle2)
    delta = Abs(angle1-angle2)
    return (delta < threshold) or (delta > Pi-threshold)

Collinear(A,B, C,D)
    return Nea开发者_如何学JAVArlyParallel(Angle(A,C), Angle(B,D)) and NearlyParallel(Angle(A,D), Angle(B,C))

So generally I need to say which line is Collinear to which and which one is NearlyParallel to another for each line.

I need to do it in c++ using boost and any opensource library needed. I do it under windows in visual studio 2010.

What library, and its part can help me in organizing fast calculations for my data? will for example boost graph lib be helpful? I mean generally I need to perform some thread/processors optimizations for speeding up. And I will not have any fancy video card to perform that all...


You could use your Angle function on every line and store the result in a std::map, using the angle as the key. That will bring lines with similar angles close together, so you can quickly choose pairs to test for NearlyParallel and Collinear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜