Project1
标题:
沙茶代码求测试
[打印本页]
作者:
yangff
时间:
2011-6-17 22:59
标题:
沙茶代码求测试
本帖最后由 yangff 于 2011-6-18 09:26 编辑
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
复制代码
作者:
糖克鸡
时间:
2011-6-19 16:26
就是那啥圆周的计算= =?
作者:
yangff
时间:
2011-6-19 17:42
糖克鸡 发表于 2011-6-19 16:26
就是那啥圆周的计算= =?
已经证明本代码是错误的了
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1