lib/geometry2D.rb in xrvg-0.0.5 vs lib/geometry2D.rb in xrvg-0.0.6
- old
+ new
@@ -1,11 +1,11 @@
#
# Contains Ruby geometric V2D 2D class.
# See :
# - +V2D+
-require 'Attributable'
+require 'attributable'
module XRVG
#
# 2D vector
#
@@ -125,12 +125,12 @@
# compute the angle of a vector considering x axis.
# V2D[0.0,2.0].angle => 0.0
def angle
r = self.r()
- if r == 0
- return 0
+ if r == 0.0
+ return 0.0
else
unitary = self/r
cos, sin = unitary.x, unitary.y
angle = Math.acos( cos )
if sin < 0.0
@@ -172,9 +172,16 @@
# compute the symetric of vector "other" considering self as symetry center
# V2D[1.0,2.0].sym( V2D[0.0,0.0] ) => V2D[2.0,4.0]
def sym( other )
return self * 2.0 - other
+ end
+
+ # compute the symetric of point "self" considering (point,v) as symetry axis
+ def axesym( point, axev )
+ v = self - point
+ angle = V2D.angle( v, axev )
+ return point + v.rotate( -2.0 * angle )
end
# coords management between different coord systems (for the moment only euclidian and polar)
# V2D[0.0,1.0].coords => [0.0,1.0]
# V2D[0.0,1.0].coords(:polar) => [1.0,Math::PI/2.0]