Created
December 12, 2008 12:18
-
-
Save hitode909/35095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
def area_circle(circle) | |
circle.radius ** 2 * Math::PI | |
end | |
def dist_pos(pos1, pos2) | |
diffx = pos1.x - pos2.x | |
diffy = pos1.y - pos2.y | |
Math::sqrt(diffx ** 2 + diffy ** 2) | |
end | |
def circle_include_pos(cir, pos) | |
cir.radius > dist_pos(cir.center, pos) | |
end | |
# 座標を作って管理できるようにする | |
position = Struct.new("Position", :x, :y) | |
pos1 = position.new(0, 0) | |
puts pos1 | |
# 2つの座標の距離 | |
pos2 = position.new(2, 0) | |
puts "#{pos1}と#{pos2}の距離:#{dist_pos(pos1, pos2)}" | |
# 円を作って管理できるようにする | |
circle = Struct.new("Circle", :center, :radius) | |
cir1 = circle.new(position.new(0.0, 0.0), 1.0) | |
puts cir1 | |
puts "面積#{area_circle(cir1)}" | |
puts circle_include_pos(cir1, pos1) | |
puts circle_include_pos(cir1, pos2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment