Skip to content

Commit a76127a

Browse files
committed
more Vec2D library comment
1 parent fcfdcc0 commit a76127a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

processing_app/library/vecmath/vec2d/circumcircle.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,27 @@ translate(0, -height)
99
But that will mess up any text (plus you probably need to `push_matrix` and `pop_matrix`) so it is probably simpler to create a parallel coordinate system for the math, and translate that back to the screen (using the processing `map` function or in `propane` and `JRubyArt` use `map1d`).
1010

1111
We have done this in `circumcircle_sketch.rb` or just accept the processing coordinate system as we have with `basic_cirmcumcircle_sketch.rb` (it is much simpler).
12+
13+
### PVector limitations ###
14+
15+
PVector is a 3D vector, that is often used as a 2D vector, to my mind that is just plain wrong. If you evaluate the cross product of a 2D vector you get a float (you may see somewhere that a cross product does not exist for 2D vectors, but it can be useful). The cross product of PVector yields another PVector, so cannot be used in the calculation of the area of the triangle as defined by two vectors _cf_ Vec2D:-
16+
17+
```ruby
18+
a = Vec2D.new(100, 0)
19+
b = Vec2D.new(0, 100)
20+
21+
a.cross(b).abs == 10_000 # or twice the area of the triangle enclosed by a, b
22+
23+
```
24+
Further we can use the cross product in a test for collinearity
25+
26+
```ruby
27+
28+
# given 3 points in 2D space
29+
a = Vec2D.new(0, 0)
30+
b = Vec2D.new(100, 100)
31+
c = Vec2D.new(200, 200)
32+
33+
(a - b).cross(b - c) == 0 # the area of the triangle is zero, so a, b, c are collinear
34+
35+
```

0 commit comments

Comments
 (0)