| 赞 | 12  | 
 
| VIP | 107 | 
 
| 好人卡 | 6 | 
 
| 积分 | 4 | 
 
| 经验 | 31122 | 
 
| 最后登录 | 2024-6-29 | 
 
| 在线时间 | 1606 小时 | 
 
 
 
 
 
Lv2.观梦者 傻♂逼 
	- 梦石
 - 0 
 
        - 星屑
 - 374 
 
        - 在线时间
 - 1606 小时
 
        - 注册时间
 - 2007-3-13
 
        - 帖子
 - 6562
 
 
   
 
 | 
	
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员  
 
x
 
- module CV
 
 -         module_function
 
 -         class Point
 
 -                 def initialize(x,y)
 
 -                         @x=x.to_f
 
 -                         @y=y.to_f
 
 -                 end
 
 -                 def x
 
 -                         return @x
 
 -                 end
 
 -                 def y
 
 -                         return @y
 
 -                 end
 
 -                 def x=(v)
 
 -                         return (@x=v)
 
 -                 end
 
 -                 def y=(v)
 
 -                         return (@y=v)
 
 -                 end
 
  
-                 def in_polygon(p)
 
 -                         p=p.points
 
 -                         nCross=0
 
 -                         for i in 0...p.size
 
 -                                 p1=p[i]
 
 -                                 p2=p[(i+1) % p.size]
 
 -                                 next if p1.y == p2.y
 
 -                                 next if y < [p1.y, p2.y].min
 
 -                                 next if y >= [p1.y, p2.y].max
 
 -                                 
 
 -                                 x1=(y - p1.y)*(p2.x - p1.x)/(p2.y - p1.y) + p1.x
 
 -                                 #p  (p2.y - p1.y)
 
 -                                 nCross+=1 if x1>x
 
 -                         end
 
 -                         #p nCross
 
 -                         return (nCross % 2 == 1)
 
 -                 end
 
 -         end
 
 -         class Grap
 
 -         
 
 -         end
 
 -         class Polygon<Grap
 
 -                 def initialize(*args)
 
 -                         @points=args
 
 -                 end
 
 -                 def points
 
 -                         return @points
 
 -                 end
 
 -                 def &(v)
 
 -                         if v.is_a?(Grap)
 
 -                                 if v.is_a?(Polygon)
 
 -                                         for i in @points
 
 -                                                 if i.in_polygon(v)==true
 
 -                                                         return true
 
 -                                                 end
 
 -                                         end
 
 -                                         for i in v.points
 
 -                                                 if i.in_polygon(self)==true
 
 -                                                         return true
 
 -                                                 end
 
 -                                         end
 
 -                                 end
 
 -                         end
 
 -                         return false
 
 -                 end
 
 -         end
 
 -         class Vector
 
 -                 
 
 -         end
 
  
- end
 
 - poy=CV::Polygon.new(CV::Point.new(0,0),CV::Point.new(1,2),CV::Point.new(5,5),CV::Point.new(5,15))
 
 - poy1=CV::Polygon.new(CV::Point.new(300,500),CV::Point.new(100,200),CV::Point.new(500,500),CV::Point.new(500,1500))
 
 - p poy&poy1
 
  复制代码 效率一般……没做粗判定…… |   
 
 
 
 |