Skip to content

Commit d25359a

Browse files
committed
Replace 2D cross product with wedge product
1 parent 77a56bb commit d25359a

File tree

16 files changed

+175
-18
lines changed

16 files changed

+175
-18
lines changed

contributed/circles.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def draw
2222
end
2323

2424
# set the style of the circle
25-
@dc = map1d(millis, 0..150_000, 0..360) # slowly changes hue
26-
stroke((@c + @dc) % 360, 50, 100, 5)
25+
@delta_hue = map1d(millis, 0..150_000, 0..360) # slowly changes hue
26+
stroke((@hue + @delta_hue) % 360, 50, 100, 5)
2727
no_fill
2828

2929
## verifies if there is a circle and draw it
@@ -39,7 +39,7 @@ def draw_circle(pts)
3939
end
4040

4141
def reset
42-
@c = rand(360)
42+
@hue = rand(360)
4343
@points = TrianglePoints.new
4444
3.times { @points << TPoint.new(Vec2D.new(rand(5..width - 5), rand(5..height - 5))) }
4545
background 0

contributed/elegant_ball.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ def draw_triangle(depth, r, p1, p2, p3)
134134
v3 = (p3 + p1) * 0.5
135135
unless r == 0.0
136136
# Project the vertices out onto the sphere with radius r.
137-
v1.normalize!
138-
v1 *= r
139-
v2.normalize!
140-
v2 *= r
141-
v3.normalize!
142-
v3 *= r
137+
v1.set_mag(r)
138+
v2.set_mag(r)
139+
v3.set_mag(r)
143140
end
144141
## Generate the next level of detail
145142
depth -= 1

contributed/library/circle/lib/t_points.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def <<(pt)
2020
end
2121

2222
def collinear?
23-
full? ? (positions[0] - positions[1]).cross(positions[1] - positions[2]).zero? : false
23+
full? ? ((positions[0] - positions[1]) ^ (positions[1] - positions[2])).zero? : false
2424
end
2525

2626
# returns positions as an array of Vec2D

processing_app/library/vecmath/vec2d/basic_circumcircle_sketch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Here is a sketch that clearly demonstrates some of the most egregious parts of
44
# vanilla processing:-
55
# PVector is over complicated and overloads 2D and 3D functionality, cf Vec2D
6-
# JRubyArt and propane which behaves as a 2D vector (cross product is a float)
6+
# JRubyArt and propane which behaves as a 2D vector (wedge product is a float)
77
# and can easily be used in chain calculations.
88

99
##################################################

processing_app/library/vecmath/vec2d/circles.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def draw
3131
no_fill
3232
# verifies if there is a circle and draw it
3333
return if collinear(@points[0].pos, @points[1].pos, @points[2].pos)
34-
draw_circle *@points
34+
draw_circle(*@points)
3535
end
3636

3737
def draw_circle(a, b, c)
@@ -53,7 +53,7 @@ def bisector(a, b)
5353
end
5454

5555
def collinear(a, b, c)
56-
(a - b).cross(b - c).zero?
56+
((a - b) ^ (b - c)).zero?
5757
end
5858

5959
def center(bisector)

processing_app/library/vecmath/vec2d/library/circle/lib/points.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def <<(pt)
2121

2222
def collinear?
2323
return false unless full?
24-
(array[0] - array[1]).cross(array[1] - array[2]).zero?
24+
((array[0] - array[1]) ^ (array[1] - array[2])).zero?
2525
end
2626

2727
def array

0 commit comments

Comments
 (0)