Skip to content

Metloff/easy_geometry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geometry for Ruby

Gem Version

EasyGeometry gem allows one to create two-dimensional geometrical entities, such as lines and polygons, and query for information about these entities. This could include asking the area of an polygon, checking for collinearity of a set of points, or finding the intersection between two lines.

Available geometry entities

  • Point, Vector
  • Line, Segment, Ray
  • Polygon, Triangle

Installation

gem install easy_geometry

Examples

x = EasyGeometry::D2::Point.new(0, 0)
y = EasyGeometry::D2::Point.new(1, 1)
z = EasyGeometry::D2::Point.new(2, 2)
w = EasyGeometry::D2::Point.new(1, 0)

EasyGeometry::D2::Point.is_collinear?(x, y, z) # true
EasyGeometry::D2::Point.is_collinear?(x, y, w) # false

t = EasyGeometry::D2::Triangle.new(x, y, w)
t.area      # 0.5
t.perimeter # 3.414213562373095

s1 = EasyGeometry::D2::Segment.new([0, 0], [1, 1])
s2 = EasyGeometry::D2::Segment.new([0, 0], [-1, 1])
s3 = EasyGeometry::D2::Segment.new([0, 0], [1, 0])
s1.midpoint         # Point(1/2, 1/2)
s3.length           # 1
s1.intersection(s2) # [Point(0, 0)]

You can find more examples in documentetion and in specs directory.

License

2019 Henry Metlov, released under the MIT license

About

Two-dimensional geometry on ruby

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages