math_demo 0.1.1-java
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/bin/math_demo +4 -0
- data/lib/circles.rb +55 -0
- data/lib/math_demo/circumcircle.rb +43 -0
- data/lib/math_demo/matrix_math.md +17 -0
- data/lib/math_demo/t_points.rb +34 -0
- data/lib/math_demo/triangle_point.rb +46 -0
- data/lib/math_demo/version.rb +5 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8de551cf7d2d012e7c911d9791275bc9fc148f3b
|
4
|
+
data.tar.gz: 54a206138d996cbdd27defa13b733dc2082c8b66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 418e38407f76a4e4c9fc98f41b5e9662488b4ba4f11a9c34264f1825f335b6972339576d99c125e0495758aea69b2c2321a1af4e606ba8942f15cee292b3f4c2
|
7
|
+
data.tar.gz: 39058c2742e86a038f9a7b45c350041d450267e58c8c7af12240b64066eb82f34b996fcd2cba2579e8bdb3006d1ebc3e220f79a2842989d871746a3d5ba12043
|
data/bin/math_demo
ADDED
data/lib/circles.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
require 'propane'
|
3
|
+
require_relative 'math_demo/circumcircle'
|
4
|
+
require_relative 'math_demo/t_points'
|
5
|
+
require_relative 'math_demo/triangle_point'
|
6
|
+
|
7
|
+
class Circles < Propane::App
|
8
|
+
|
9
|
+
def settings
|
10
|
+
size(800, 600, P2D)
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
sketch_title 'Circles'
|
15
|
+
color_mode(HSB, 360, 100, 100, 100)
|
16
|
+
reset
|
17
|
+
ellipse_mode(RADIUS)
|
18
|
+
end
|
19
|
+
|
20
|
+
def draw
|
21
|
+
fill(0, 0, 0)
|
22
|
+
no_stroke
|
23
|
+
reset if (frame_count % 8_000).zero?
|
24
|
+
@points.each do |point|
|
25
|
+
# change direction sometimes
|
26
|
+
point.direction Vec2D.random if rand > 0.96
|
27
|
+
point.update
|
28
|
+
end
|
29
|
+
|
30
|
+
# set the style of the circle
|
31
|
+
@dc = map1d(millis, 0..150_000, 0..360) # slowly changes hue
|
32
|
+
stroke((@c + @dc) % 360, 50, 100, 5)
|
33
|
+
no_fill
|
34
|
+
|
35
|
+
## verifies if there is a circle and draw it
|
36
|
+
draw_circle @points unless @points.collinear?
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw_circle(pts)
|
40
|
+
circumcircle = Circumcircle.new(@points.positions)
|
41
|
+
circumcircle.calculate
|
42
|
+
center_point = circumcircle.center
|
43
|
+
radius = circumcircle.radius
|
44
|
+
ellipse(center_point.x, center_point.y, radius, radius)
|
45
|
+
end
|
46
|
+
|
47
|
+
def reset
|
48
|
+
@c = rand(360)
|
49
|
+
@points = TrianglePoints.new
|
50
|
+
3.times { @points << TPoint.new(Vec2D.new(rand(5..width - 5), rand(5..height - 5))) }
|
51
|
+
background 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Circles.new
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Circumcircle from 3 points
|
2
|
+
require 'matrix'
|
3
|
+
|
4
|
+
class Circumcircle
|
5
|
+
attr_reader :center, :radius, :points
|
6
|
+
def initialize(points)
|
7
|
+
@points = points
|
8
|
+
end
|
9
|
+
|
10
|
+
def calculate
|
11
|
+
@center = Vec2D.new(-(bx / am), -(by / am))
|
12
|
+
@radius = center.dist(points[2]) # points[2] = c
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Matrix math see matrix_math.md and in detail
|
18
|
+
# http://mathworld.wolfram.com/Circumcircle.html
|
19
|
+
|
20
|
+
def am
|
21
|
+
2 * Matrix[
|
22
|
+
[points[0].x, points[0].y, 1],
|
23
|
+
[points[1].x, points[1].y, 1],
|
24
|
+
[points[2].x, points[2].y, 1]
|
25
|
+
].determinant
|
26
|
+
end
|
27
|
+
|
28
|
+
def bx
|
29
|
+
-Matrix[
|
30
|
+
[points[0].x * points[0].x + points[0].y * points[0].y, points[0].y, 1],
|
31
|
+
[points[1].x * points[1].x + points[1].y * points[1].y, points[1].y, 1],
|
32
|
+
[points[2].x * points[2].x + points[2].y * points[2].y, points[2].y, 1]
|
33
|
+
].determinant
|
34
|
+
end
|
35
|
+
|
36
|
+
def by
|
37
|
+
Matrix[
|
38
|
+
[points[0].x * points[0].x + points[0].y * points[0].y, points[0].x, 1],
|
39
|
+
[points[1].x * points[1].x + points[1].y * points[1].y, points[1].x, 1],
|
40
|
+
[points[2].x * points[2].x + points[2].y * points[2].y, points[2].x, 1]
|
41
|
+
].determinant
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
### Matrix Math ###
|
2
|
+
|
3
|
+
For detailed workings see [Circumcircle at Mathworld Wolfram.com][circumcircle]
|
4
|
+
|
5
|
+
|
6
|
+
a = {{x<sub>1</sub> y<sub>1</sub> 1}, {x<sub>2</sub> y<sub>2</sub> 1}, {x<sub>3</sub> y<sub>3</sub> 1}}
|
7
|
+
|
8
|
+
bx = -{{x<sub>1</sub><sup>2</sup> + y<sub>1</sub><sup>2</sup> y<sub>1</sub> 1}, {x<sub>2</sub><sup>2</sup> + y<sub>2</sub><sup>2</sup> y<sub>2</sub> 1}, {x<sub>3</sub><sup>2</sup> + y<sub>3</sub><sup>2</sup> y<sub>3</sub> 1}}
|
9
|
+
|
10
|
+
by = {{x<sub>1</sub><sup>2</sup> + y<sub>1</sub><sup>2</sup> x<sub>1</sub> 1}, {x<sub>2</sub><sup>2</sup> + y<sub>2</sub><sup>2</sup> x<sub>2</sub> 1}, {x<sub>3</sub><sup>2</sup> + y<sub>3</sub><sup>2</sup> x<sub>3</sub> 1}}
|
11
|
+
|
12
|
+
xo = -bx / 2 * a
|
13
|
+
|
14
|
+
yo = -by / 2 * a
|
15
|
+
|
16
|
+
|
17
|
+
[circumcircle]:http://mathworld.wolfram.com/Circumcircle.html
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'forwardable'
|
3
|
+
MAX_POINT = 3
|
4
|
+
# A collection of a maximum of 3 points in the processing world
|
5
|
+
# includes a collinearity test using Vec2D
|
6
|
+
class TrianglePoints
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators(:@points, :each, :map, :size, :shift, :clear, :[])
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
attr_reader :points
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@points = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def <<(pt)
|
18
|
+
points << pt
|
19
|
+
shift if size > MAX_POINT
|
20
|
+
end
|
21
|
+
|
22
|
+
def collinear?
|
23
|
+
full? ? (positions[0] - positions[1]).cross(positions[1] - positions[2]).zero? : false
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns positions as an array of Vec2D
|
27
|
+
def positions
|
28
|
+
points.map(&:pos)
|
29
|
+
end
|
30
|
+
|
31
|
+
def full?
|
32
|
+
points.length == MAX_POINT
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# particle and triangle point
|
3
|
+
class TPoint
|
4
|
+
include Propane::Proxy
|
5
|
+
attr_reader :pos, :vel, :accel, :xbound, :ybound
|
6
|
+
# attr_reader :width, :height # uncomment for testing
|
7
|
+
|
8
|
+
def initialize(position)
|
9
|
+
@pos = position
|
10
|
+
@vel = Vec2D.new
|
11
|
+
@accel = Vec2D.random
|
12
|
+
@xbound = Boundary.new(0, width)
|
13
|
+
@ybound = Boundary.new(0, height)
|
14
|
+
end
|
15
|
+
|
16
|
+
def direction(acc)
|
17
|
+
# direction of the acceleration is defined by the new angle
|
18
|
+
@accel = acc
|
19
|
+
# magnitude of the acceleration is proportional to the angle between
|
20
|
+
# acceleration and velocity
|
21
|
+
dif = acc.angle_between(vel)
|
22
|
+
dif = map1d(dif, 0..PI, 0.1..0.001)
|
23
|
+
@accel = acc * dif
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
@vel += accel
|
28
|
+
@vel.set_mag(1.5) { vel.mag > 1.5 }
|
29
|
+
@pos += vel
|
30
|
+
check_bounds
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def check_bounds
|
36
|
+
@vel.x *= -1 if xbound.exclude? pos.x
|
37
|
+
@vel.y *= -1 if ybound.exclude? pos.y
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# we are looking for excluded values
|
42
|
+
Boundary = Struct.new(:lower, :upper) do
|
43
|
+
def exclude?(val)
|
44
|
+
true unless (lower...upper).cover? val
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: math_demo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- monkstone
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: propane
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.8'
|
55
|
+
description: " Math Demo uses propane (a ruby wrapper for the processing art framework)\n"
|
56
|
+
email: mamba2928@yahoo.co.uk
|
57
|
+
executables:
|
58
|
+
- math_demo
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- bin/math_demo
|
63
|
+
- lib/circles.rb
|
64
|
+
- lib/math_demo/circumcircle.rb
|
65
|
+
- lib/math_demo/matrix_math.md
|
66
|
+
- lib/math_demo/t_points.rb
|
67
|
+
- lib/math_demo/triangle_point.rb
|
68
|
+
- lib/math_demo/version.rb
|
69
|
+
homepage: https://ruby-processing.github.io/propane/
|
70
|
+
licenses:
|
71
|
+
- GPL-3.0
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.3'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements:
|
88
|
+
- A decent graphics card
|
89
|
+
- java runtime >= 1.8.0_111+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.6.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Example of creating a propane app.
|
95
|
+
test_files: []
|