在一个固定的区域随便画4条线。然后用鼠标框选一个区域。需要达到的目标是选中经过该区域的所有直线。这个算法怎么实现?

解决方案 »

  1.   

    类似拾取,你在画这4条线的时候首先要构建每条线的特性,例如线段就是起始、终止点的坐标,然后拾取这个线条的算法就可以根据这两个点计算了,可以通过斜率计算是否有包容的点即可。类似CAD,我的CSDN BLOG中有部分CAD的内容
      

  2.   

    You have to do hit test.But there are optimizations for complex scene, like Bounding Box,           // a bounding box is rectangle one, so it is easier for pre-intersect-detection than a circle
    Spatial partitioning,   // divide the space into sub-spaces and hit-test within the smaller area
    Temporal coherence,     // a far away object is unlikely to intersect the next moment
    ...
      

  3.   

    线性代数的"矩阵", 不知道楼主有没有学过.一条线段的方程是y=ax+b(x1<x<x2)你是一个4个2元一次方程的方程组, 也就是一个矩阵.求解即可.