查看: 1397|回复: 2

[已经过期] 沙茶代码求测试

  [复制链接]

傻♂逼

梦石
0
星屑
374
在线时间
1606 小时
注册时间
2007-3-13
回帖
6005

烫烫烫开拓者

发表于 2011-6-17 22:59:47 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 yangff 于 2011-6-18 09:26 编辑
  1. module YMath
  2.   
  3.   class MathObject
  4.     def self.kind(*args)
  5.       if args.size>0
  6.         @kind=args[0]
  7.       else
  8.         return @kind
  9.       end
  10.     end
  11.   end
  12.   class ScreenSystem < MathObject
  13.     attr_reader:width
  14.     attr_reader:height
  15.     def initialize(width,height)
  16.       @width=width.to_f
  17.       @height=height.to_f
  18.     end
  19.     class Point<MathObject
  20.       attr_reader:x
  21.       attr_reader:y
  22.       attr_reader:ss
  23.       def initialize(x,y,ss)
  24.         @x=x.to_f
  25.         @y=y.to_f
  26.         @ss=ss
  27.       end
  28.       def to_ccs
  29.         CartesianCoordinateSystem::Point.new(@x-@ss.width/2.0,@y-@ss.height/2.0)
  30.       end
  31.       def to_pcs
  32.         to_ccs.to_pcs
  33.       end
  34.     end   
  35.   end
  36.   class PolarCoordinateSystem<MathObject
  37.     class Point<MathObject
  38.       attr_reader:r
  39.       attr_reader:xita
  40.       def initialize(r,xita)
  41.         @r=r.to_f
  42.         @xita=xita.to_f
  43.       end
  44.       def to_ccs
  45.         CartesianCoordinateSystem::Point.new(r*Math.cos(xita),r*Math.sin(xita))
  46.       end
  47.       def to_ss(ss)
  48.         to_ccs.to_ss(ss)
  49.       end
  50.     end
  51.   end
  52.   class CartesianCoordinateSystem<MathObject
  53.     class Point < MathObject
  54.       kind:ccs
  55.       attr_reader:x
  56.       attr_reader:y
  57.       def initialize(x,y)
  58.         @x=x.to_f
  59.         @y=y.to_f
  60.       end
  61.       def to_pcs
  62.         xita=Math.atan(@y/@x) if x!=0
  63.         xita=Math::PI/2.0 if x==0 and  y>0
  64.         xita=(3*Math::PI)/2.0 if x==0 and y<0
  65.         xita=0 if x==0 and y==0
  66.         PolarCoordinateSystem::Point.new(Math.sqrt(x**2+y**2),xita)
  67.       end
  68.       def to_ss(ss)
  69.         ScreenSystem::Point.new(ss.width/2.0+@x,ss.height/2.0+@y,ss)
  70.       end
  71.         
  72.     end
  73.   end
  74.   class Ellipse < MathObject
  75.     attr_reader :a
  76.     attr_reader :b
  77.     attr_reader :c
  78.     kind :pcs
  79.     def initialize(long,short,rotate=0)
  80.       @a=long.to_f/2.0
  81.       @b=short.to_f/2.0
  82.       @c=Math.sqrt(a**2-b**2).to_f
  83.       @e=@c/@a
  84.       @p=a**2/@c-@c
  85.       @rotate=rotate
  86.     end
  87.     def r(xita)
  88.       return PolarCoordinateSystem::Point.new((@e*@p)/(1-@e*Math.cos(xita+@rotate)),xita)
  89.     end
  90.   end
  91.   class Circle < MathObject
  92.     kind :pcs
  93.     attr_reader:r
  94.     def initialize(r)
  95.       @r=r
  96.     end
  97.     def r(xita)
  98.       return @r
  99.     end
  100.   end
  101. end
复制代码
哎呀,蛋疼什么的最有爱了
梦石
0
星屑
50
在线时间
25 小时
注册时间
2011-1-1
回帖
79
发表于 2011-6-19 16:26:16 | 显示全部楼层
就是那啥圆周的计算= =?
(本消息由该成员通过66rpg发送,体验请登录:   http://rpg.blue/ )  
回复

使用道具 举报

傻♂逼

梦石
0
星屑
374
在线时间
1606 小时
注册时间
2007-3-13
回帖
6005

烫烫烫开拓者

 楼主| 发表于 2011-6-19 17:42:40 | 显示全部楼层
糖克鸡 发表于 2011-6-19 16:26
就是那啥圆周的计算= =?

已经证明本代码是错误的了
哎呀,蛋疼什么的最有爱了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部