| 
 
| 赞 | 12 |  
| VIP | 107 |  
| 好人卡 | 6 |  
| 积分 | 4 |  
| 经验 | 31122 |  
| 最后登录 | 2024-6-29 |  
| 在线时间 | 1606 小时 |  
 Lv2.观梦者 傻♂逼 
	梦石0 星屑374 在线时间1606 小时注册时间2007-3-13帖子6562  
 | 
| 
本帖最后由 yangff 于 2011-6-18 09:26 编辑
x
加入我们,或者,欢迎回来。您需要 登录 才可以下载或查看,没有帐号?注册会员  
 复制代码module YMath
  
  class MathObject
    def self.kind(*args)
      if args.size>0
        @kind=args[0]
      else
        return @kind
      end
    end
  end
  class ScreenSystem < MathObject
    attr_reader:width
    attr_reader:height
    def initialize(width,height)
      @width=width.to_f
      @height=height.to_f
    end
    class Point<MathObject
      attr_reader:x
      attr_reader:y
      attr_reader:ss
      def initialize(x,y,ss)
        @x=x.to_f
        @y=y.to_f
        @ss=ss
      end
      def to_ccs
        CartesianCoordinateSystem::Point.new(@[email protected]/2.0,@[email protected]/2.0)
      end
      def to_pcs
        to_ccs.to_pcs
      end
    end    
  end
  class PolarCoordinateSystem<MathObject
    class Point<MathObject
      attr_reader:r
      attr_reader:xita
      def initialize(r,xita)
        @r=r.to_f
        @xita=xita.to_f
      end
      def to_ccs
        CartesianCoordinateSystem::Point.new(r*Math.cos(xita),r*Math.sin(xita))
      end
      def to_ss(ss)
        to_ccs.to_ss(ss)
      end
    end
  end
  class CartesianCoordinateSystem<MathObject
    class Point < MathObject
      kind:ccs
      attr_reader:x
      attr_reader:y
      def initialize(x,y)
        @x=x.to_f
        @y=y.to_f
      end
      def to_pcs
        xita=Math.atan(@y/@x) if x!=0
        xita=Math::PI/2.0 if x==0 and  y>0
        xita=(3*Math::PI)/2.0 if x==0 and y<0
        xita=0 if x==0 and y==0
        PolarCoordinateSystem::Point.new(Math.sqrt(x**2+y**2),xita)
      end
      def to_ss(ss)
        ScreenSystem::Point.new(ss.width/2.0+@x,ss.height/2.0+@y,ss)
      end
        
    end
  end
  class Ellipse < MathObject
    attr_reader :a
    attr_reader :b
    attr_reader :c
    kind :pcs
    def initialize(long,short,rotate=0)
      @a=long.to_f/2.0
      @b=short.to_f/2.0
      @c=Math.sqrt(a**2-b**2).to_f
      @e=@c/@a
      @p=a**2/@c-@c
      @rotate=rotate
    end
    def r(xita)
      return PolarCoordinateSystem::Point.new((@e*@p)/(1-@e*Math.cos(xita+@rotate)),xita)
    end
  end
  class Circle < MathObject
    kind :pcs
    attr_reader:r
    def initialize(r)
      @r=r
    end
    def r(xita)
      return @r
    end
  end
end
 | 
 |