rubyllipse 1.0.0 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -0
  3. data/lib/rubyllipse.rb +102 -1
  4. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 234aac93632e7a7f43c1788e72eea0fb3ca700035965942bb4a122fa190ba539
4
- data.tar.gz: 75af9f59827cc2c8998f9ba12f42bf35bd8a19a174b6b5eb8c03e96a34eec44b
3
+ metadata.gz: 3738c04c84d4f5266f64bc14349d7c5e781a80da94eba257398dd986ba85afb8
4
+ data.tar.gz: f381cca3160f7bb0119afc2686f98404984dea1aa6c73dd2c9e4a94cac4f319a
5
5
  SHA512:
6
- metadata.gz: de4894844093f76e88aaa5f17707051b903aeaee34c3e75e6b387ed9ccfa083f5c308bf99b991b2052f6b79619a7631ddc87946fa4ea7e9a24231c9b7373c6fd
7
- data.tar.gz: 988b8059eaf608b202f23705808bfe9fb2bc1fb3c608d1faa290c6ff092acf37fcfbd3a33f2675fd0c104c06720735abff95c7c2b1e69e94fd37bd3c35b73f07
6
+ metadata.gz: 5c059eb8eb22d82b2b5ab3ff00c0c3cb967541c2d36a556db78edc4908d6b872580c99fb72fe38ded41fc0bf3c10443ae03cfe95399595d53c8021f2bee3d758
7
+ data.tar.gz: 0d28b11b78d542c37910635a15f16586f6d8c8c798d6b0887a9c9d8707fd16df89683f1c628b4466b8e040c1c8cafe5806b7cfc61f856c288a4cd9e44797a4d1
@@ -0,0 +1,27 @@
1
+ # Rubyllipse
2
+ Yes, I know the name's dumb.
3
+
4
+ A simple gem for managing and playing with ellipses.
5
+
6
+ ## Usage
7
+
8
+ Create a new ```Ellipse``` object: ```Rubyllipse::Ellipse::new(major_radius, minor_radius, center_coordinates)```; ```myellipse = Rubyllipse::Ellipse::new(3, 3, [0,0])```.
9
+
10
+ ```myellipse.is_circle? == True``` as we can see we just created a circle. ```myellipse.area```, ```myellipse.perimeter``` will return the circle's area, perimeter.
11
+
12
+ ```myellipse.move_horizontally(3)``` will move the ellipse by 3 units towards the positive horizontal way and reinitialize the ```myellipse``` object.
13
+
14
+ One of the most important aspects of an ```Ellipse``` object is the ```form``` attribute. it can be either set to ```'horizontal'``` or ```'vertical'``` and it determines if the ellipse's major-axis will be vertical or horizontal (tilted, rotated ellipses are not available yet).
15
+
16
+ Another important method is ```give_function!```. It returns a string for the purpose of mainly displaying the function of the ```Ellipse``` object.
17
+
18
+ You can easily find a point by using the ```get_ordinates_for(abscissa)``` for example: ```Rubyllipse::Ellipse::new(10, 2, [3,3], form:'vertical')::get_ordinates_for(3)``` will return ```[13.0, -7]``` and ```get_abscissas_for(ordinate)``` is what you think it is. (Added in 1.0.4 and 1.0.5)
19
+
20
+ You can also compute the points of intersection for the ellipse and the x, y axis with; ```Ellipse.pointsof_intersection_for_x``` and ```Ellipse.pointsof_intersection_for_y```. (added in 1.0.5)
21
+
22
+ Other methods are for accessing the object's attributes and don't need further explanation.
23
+
24
+
25
+ ## Notes
26
+ If you used the module and found something odd, bad, please send me an e-mail; I am still new to Ruby.
27
+
@@ -14,6 +14,9 @@ module Rubyllipse
14
14
  elsif @form == 'vertical'
15
15
  @vertexes = [[@center[0], @center[0]+@major_radius], [@center[0], @center[0]-@major_radius]]
16
16
  @co_vertexes = [[@center[0]+@minor_radius, @center[1]], [@center[0]-@minor_radius, @center[1]]]
17
+ elsif @form == 'tilted'
18
+ @vertexes = vertexes
19
+ @co_vertexes = co_vertexes
17
20
  end
18
21
 
19
22
  @radii = [@major_radius, @minor_radius]
@@ -29,6 +32,8 @@ module Rubyllipse
29
32
  @focii = [[@center[0]+@focal_length, @center[1]], [@center[0]-@focal_length, @center[1]]]
30
33
  elsif @form == 'vertical'
31
34
  @focii = [[@center[0], @center[1]+@focal_length], [@center[0], @center[1]-@focal_length]]
35
+ elsif @form == 'tilted'
36
+ @focii = focii
32
37
  end
33
38
 
34
39
  @eccentricity = Float(@focal_length)/@major_radius
@@ -69,6 +74,14 @@ module Rubyllipse
69
74
  def eccentricity
70
75
  return @eccentricity
71
76
  end
77
+
78
+ def center
79
+ return @center
80
+ end
81
+
82
+ def form
83
+ return @form
84
+ end
72
85
 
73
86
  def give_function!
74
87
  c_x = @center[0]
@@ -80,8 +93,96 @@ module Rubyllipse
80
93
  a = @major_radius**2
81
94
  b = @minor_radius**2
82
95
  end
83
- equation = "(x-#{c_x})^2/#{a} + (y-#{c_y})^2/#{b} = 1"
96
+ equation = "(x-#{c_x})^2/#{b} + (y-#{c_y})^2/#{a} = 1"
84
97
  return equation
85
98
  end
99
+
100
+ def move_horizontally!(distance)
101
+ @center = [@center[0]+distance, @center[1]]
102
+ self.initialize(@major_radius, @minor_radius, @center, form:@form)
103
+ return
104
+ end
105
+
106
+ def move_vertically!(distance)
107
+ @center = [@center[0], @center[1]+distance]
108
+ self.initialize(@major_radius, @minor_radius, @center, form:@form)
109
+ return
110
+ end
111
+
112
+ def get_ordinates_for(abscissa)
113
+ abscissa = Float(abscissa)
114
+
115
+ c_x = @center[0]
116
+ c_y = @center[1]
117
+ if @form == 'horizontal'
118
+ a = @minor_radius**2
119
+ b = @major_radius**2
120
+ elsif @form == 'vertical'
121
+ a = @major_radius**2
122
+ b = @minor_radius**2
123
+ end
124
+
125
+ begin
126
+ ordinate1 = Math.sqrt(a)*Math.sqrt(1-((abscissa-c_x)**2/b))+c_y
127
+ ordinate2 = 2*@center[1]-ordinate1
128
+ ordinates = [ordinate1, ordinate2]
129
+ rescue
130
+ puts "this ellipse is not defined for value: #{abscissa}"
131
+ end
132
+
133
+ return ordinates
134
+ end
135
+
136
+
137
+ def get_abscissas_for(ordinate)
138
+ ordinate = Float(ordinate)
139
+
140
+ c_x = @center[0]
141
+ c_y = @center[1]
142
+ if @form == 'horizontal'
143
+ a = @minor_radius**2
144
+ b = @major_radius**2
145
+ elsif @form == 'vertical'
146
+ a = @major_radius**2
147
+ b = @minor_radius**2
148
+ end
149
+
150
+ begin
151
+ abscissa1 = Math.sqrt(b)*Math.sqrt(1-((ordinate-c_y)**2/a))+c_x
152
+ abscissa2 = 2*@center[0]-abscissa1
153
+ abscissas = [abscissa1, abscissa2]
154
+ rescue
155
+ puts "this ellipse is not defined for value: #{ordinate}"
156
+ end
157
+
158
+ return abscissas
159
+ end
160
+
161
+ def pointsof_intersection_for_y()
162
+ return [[0, self.get_ordinates_for(0)[0]], [0, self.get_ordinates_for(0)[1]]]
163
+ end
164
+
165
+ def pointsof_intersection_for_x()
166
+ return [[self.get_abscissas_for(0)[0], 0], [self.get_abscissas_for(0)[1], 0]]
167
+ end
86
168
  end
87
169
  end
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
metadata CHANGED
@@ -1,21 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyllipse
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burzum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2020-11-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
15
15
  executables: []
16
16
  extensions: []
17
- extra_rdoc_files: []
17
+ extra_rdoc_files:
18
+ - README.md
18
19
  files:
20
+ - README.md
19
21
  - lib/rubyllipse.rb
20
22
  homepage:
21
23
  licenses: []
@@ -38,5 +40,5 @@ requirements: []
38
40
  rubygems_version: 3.1.2
39
41
  signing_key:
40
42
  specification_version: 4
41
- summary: A gem for ellipses, this version excludes rotated ellipses.
43
+ summary: A gem for managing ellipses, this version still excludes rotated ellipses.
42
44
  test_files: []