rubyllipse 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/rubyllipse.rb +87 -0
- metadata +42 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 234aac93632e7a7f43c1788e72eea0fb3ca700035965942bb4a122fa190ba539
|
4
|
+
data.tar.gz: 75af9f59827cc2c8998f9ba12f42bf35bd8a19a174b6b5eb8c03e96a34eec44b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de4894844093f76e88aaa5f17707051b903aeaee34c3e75e6b387ed9ccfa083f5c308bf99b991b2052f6b79619a7631ddc87946fa4ea7e9a24231c9b7373c6fd
|
7
|
+
data.tar.gz: 988b8059eaf608b202f23705808bfe9fb2bc1fb3c608d1faa290c6ff092acf37fcfbd3a33f2675fd0c104c06720735abff95c7c2b1e69e94fd37bd3c35b73f07
|
data/lib/rubyllipse.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
module Rubyllipse
|
3
|
+
|
4
|
+
class Ellipse
|
5
|
+
def initialize(major_radius, minor_radius, center, co_vertexes:nil, vertexes:nil, radii:nil, focal_length:nil, focii:nil, eccentricity:nil, form:"horizontal")
|
6
|
+
@form = form
|
7
|
+
@major_radius = major_radius
|
8
|
+
@minor_radius = minor_radius
|
9
|
+
@center = center
|
10
|
+
|
11
|
+
if @form == 'horizontal'
|
12
|
+
@co_vertexes = [[@center[0], @center[0]+@minor_radius], [@center[0], @center[0]-@minor_radius]]
|
13
|
+
@vertexes = [[@center[0]+@major_radius, @center[1]], [@center[0]-@major_radius, @center[1]]]
|
14
|
+
elsif @form == 'vertical'
|
15
|
+
@vertexes = [[@center[0], @center[0]+@major_radius], [@center[0], @center[0]-@major_radius]]
|
16
|
+
@co_vertexes = [[@center[0]+@minor_radius, @center[1]], [@center[0]-@minor_radius, @center[1]]]
|
17
|
+
end
|
18
|
+
|
19
|
+
@radii = [@major_radius, @minor_radius]
|
20
|
+
|
21
|
+
begin
|
22
|
+
@focal_length = Math.sqrt(@major_radius**2-@minor_radius**2)
|
23
|
+
rescue Math::DomainError
|
24
|
+
puts "please pass major radius as the second argument and not first"
|
25
|
+
raise ArgumentError, "passed major radius as the second argument"
|
26
|
+
end
|
27
|
+
|
28
|
+
if @form == 'horizontal'
|
29
|
+
@focii = [[@center[0]+@focal_length, @center[1]], [@center[0]-@focal_length, @center[1]]]
|
30
|
+
elsif @form == 'vertical'
|
31
|
+
@focii = [[@center[0], @center[1]+@focal_length], [@center[0], @center[1]-@focal_length]]
|
32
|
+
end
|
33
|
+
|
34
|
+
@eccentricity = Float(@focal_length)/@major_radius
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_circle?
|
38
|
+
if @eccentricity == 0
|
39
|
+
return true
|
40
|
+
else
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def area
|
46
|
+
return @major_radius*@minor_radius*Math::PI
|
47
|
+
end
|
48
|
+
|
49
|
+
def perimeter
|
50
|
+
return 2*Math::PI*Math.sqrt((@major_radius**2+@minor_radius**2)*0.5)
|
51
|
+
end
|
52
|
+
|
53
|
+
def radii
|
54
|
+
return @radii
|
55
|
+
end
|
56
|
+
|
57
|
+
def focii
|
58
|
+
return @focii
|
59
|
+
end
|
60
|
+
|
61
|
+
def co_vertexes
|
62
|
+
return @co_vertexes
|
63
|
+
end
|
64
|
+
|
65
|
+
def vertexes
|
66
|
+
return @vertexes
|
67
|
+
end
|
68
|
+
|
69
|
+
def eccentricity
|
70
|
+
return @eccentricity
|
71
|
+
end
|
72
|
+
|
73
|
+
def give_function!
|
74
|
+
c_x = @center[0]
|
75
|
+
c_y = @center[1]
|
76
|
+
if @form == 'horizontal'
|
77
|
+
a = @minor_radius**2
|
78
|
+
b = @major_radius**2
|
79
|
+
elsif @form == 'vertical'
|
80
|
+
a = @major_radius**2
|
81
|
+
b = @minor_radius**2
|
82
|
+
end
|
83
|
+
equation = "(x-#{c_x})^2/#{a} + (y-#{c_y})^2/#{b} = 1"
|
84
|
+
return equation
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyllipse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Burzum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/rubyllipse.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubygems_version: 3.1.2
|
39
|
+
signing_key:
|
40
|
+
specification_version: 4
|
41
|
+
summary: A gem for ellipses, this version excludes rotated ellipses.
|
42
|
+
test_files: []
|