geo3d 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/lib/geo3d/version.rb +1 -1
- data/lib/vector.rb +21 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870525f0b9b488f8fe0bd03f72e679d173b40222
|
4
|
+
data.tar.gz: c9803964afa4f1cf843b9a4472b2a16aa749abf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b377f16be7634b34158dbf5b21d0960c3025a4188c1ffb1e90b905f0621063d94a0d3f5f2185e5db3dc019984065dc06f4eb05a7bc2358dad37e1fb3bf257143
|
7
|
+
data.tar.gz: 11fbe068470ca6034a2174344f5f6a33cbae544821ae5eb7136a91e3d02688ded7e672fedab991ff734d398f4f71c0dcb5be727be082b72cd6baba752af43ba4
|
data/README.md
CHANGED
@@ -18,12 +18,12 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
```
|
21
|
-
a = Geo3d::Vector.
|
22
|
-
b = Geo3d::Vector.
|
21
|
+
a = Geo3d::Vector.point 1, 0, 0
|
22
|
+
b = Geo3d::Vector.point 0, 1, 0
|
23
23
|
sum = a + b # add them together
|
24
24
|
sum *= 2 #double the vector
|
25
25
|
|
26
|
-
m = Geo3d::Matrix.translation 0, 5, 0 #create a translation matrix that transforms a points 5 units on the y-axis
|
26
|
+
m = Geo3d::Matrix.translation 0, 5, 0, #create a translation matrix that transforms a points 5 units on the y-axis
|
27
27
|
sum = m * sum #apply the transform to our vector
|
28
28
|
```
|
29
29
|
|
@@ -32,6 +32,15 @@ sum = m * sum #apply the transform to our vector
|
|
32
32
|
|
33
33
|
Describes a three dimensional point or direction. A vector has the following read/write attributes: x, y, z, w
|
34
34
|
|
35
|
+
Constructors
|
36
|
+
```
|
37
|
+
a = Geo3d::Vector.new #all attributes are initialized to zero
|
38
|
+
b = Geo3d::Vector.new x,y,z,w #initialize all attributes directly
|
39
|
+
c = Geo3d::Vector.new x,y,z #initialize x,y, and z directly and default w to zero
|
40
|
+
d = Geo3d::Vector.point x,y,z #initialize x,y, and z directly and default w to one
|
41
|
+
e = Geo3d::Vector.direction x,y,z #initialize x,y, and z directly and default w to zero
|
42
|
+
```
|
43
|
+
|
35
44
|
Vectors are overloaded with all of the basic math operations.
|
36
45
|
|
37
46
|
Addition
|
data/lib/geo3d/version.rb
CHANGED
data/lib/vector.rb
CHANGED
@@ -17,6 +17,14 @@ module Geo3d
|
|
17
17
|
@w = args[3].to_f if args.size > 3
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.point *args
|
21
|
+
self.new(*args).one_w
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.direction *args
|
25
|
+
self.new(*args).zero_w
|
26
|
+
end
|
27
|
+
|
20
28
|
def zero_w
|
21
29
|
self.class.new x, y, z, 0
|
22
30
|
end
|
@@ -25,6 +33,10 @@ module Geo3d
|
|
25
33
|
self.class.new x, y, z, 1
|
26
34
|
end
|
27
35
|
|
36
|
+
def xyz
|
37
|
+
self.class.new x, y, z
|
38
|
+
end
|
39
|
+
|
28
40
|
def to_s
|
29
41
|
to_a.compact.join ' '
|
30
42
|
end
|
@@ -42,19 +54,19 @@ module Geo3d
|
|
42
54
|
end
|
43
55
|
|
44
56
|
def + vec
|
45
|
-
self.class.new x + vec.x, y + vec.y, z + vec.z, w
|
57
|
+
self.class.new x + vec.x, y + vec.y, z + vec.z, w
|
46
58
|
end
|
47
59
|
|
48
60
|
def - vec
|
49
|
-
self.class.new x - vec.x, y - vec.y, z - vec.z, w
|
61
|
+
self.class.new x - vec.x, y - vec.y, z - vec.z, w
|
50
62
|
end
|
51
63
|
|
52
64
|
def * scalar
|
53
|
-
self.class.new x * scalar, y * scalar, z * scalar, w
|
65
|
+
self.class.new x * scalar, y * scalar, z * scalar, w
|
54
66
|
end
|
55
67
|
|
56
68
|
def / scalar
|
57
|
-
self.class.new x / scalar, y / scalar, z / scalar, w
|
69
|
+
self.class.new x / scalar, y / scalar, z / scalar, w
|
58
70
|
end
|
59
71
|
|
60
72
|
def == vec
|
@@ -98,7 +110,10 @@ module Geo3d
|
|
98
110
|
end
|
99
111
|
|
100
112
|
def lerp vec, s
|
101
|
-
self + (
|
113
|
+
l = self + (vec - self)*s
|
114
|
+
l.w = w + (vec.w - w)*s
|
115
|
+
l
|
102
116
|
end
|
103
117
|
end
|
104
|
-
end
|
118
|
+
end
|
119
|
+
|