Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fdietze/vectory
A 2D geometry library in Scala.
https://github.com/fdietze/vectory
Last synced: about 2 months ago
JSON representation
A 2D geometry library in Scala.
- Host: GitHub
- URL: https://github.com/fdietze/vectory
- Owner: fdietze
- Created: 2016-11-16T11:32:52.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-20T15:57:00.000Z (2 months ago)
- Last Synced: 2024-10-20T18:25:16.173Z (2 months ago)
- Language: Scala
- Homepage:
- Size: 239 KB
- Stars: 12
- Watchers: 5
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vectory
A 2D geometry library for Scala.
## Dependency
With [JitPack](https://jitpack.io), it is common to point to a specific commit to make your builds reproducible:
```scala
resolvers += ("jitpack" at "https://jitpack.io")
libraryDependencies += "com.github.fdietze.vectory" %% "vectory" % "b349c76"// With ScalaJS:
libraryDependencies += "com.github.fdietze.vectory" %%% "vectory" % "b349c76"
```To use it in Ammonite:
```scala
import $repo.`https://jitpack.io`
import $ivy.`com.github.fdietze.vectory::vectory:b349c76`, vectory._
```## Examples
```scala
import vectory._Vec2(1,2) + Vec2(3,4) // Vec2(4.0,6.0)
Vec2(1,2).length // 2.23606797749979
Vec2(1,2).normalized // Vec2(0.4472135954999579,0.8944271909999159)
Vec2(1,2).angle // 1.1071487177940904
Vec2(1,2) dot Vec2(3,4) // 11.0
Vec2(1,2) cross Vec2(3,4) // -2.0
Vec2(1,2) * 5 // Vec2(5.0,10.0)val a = Line(Vec2(1, 3), Vec2(4, 1))
val b = Line(Vec2(2, 1), Vec2(3, 3))
a intersect b // Some(LineIntersection(Vec2(2.5,2.0),true,true)) -- point lies on both segmentsval c = Circle(Vec2(3, 1), 2)
val r = AARect(Vec2(1, 1), Vec2(6, 4))
c intersects r // trueval p = ConvexPolygon(IndexedSeq(Vec2(-3, 1), Vec2(-1, -2), Vec2(2, 2)))
val c = Circle(Vec2(-1, -4), 3)
p intersectsMtd c // Some(Vec2(-0.0,-1.0))val p = ConvexPolygon(Array(Vec2(-2, -2), Vec2(-3, -1), Vec2(2, -2), Vec2(1, 3)))
p.aabb // AARect(Vec2(-0.5,0.5),Vec2(5.0,5.0))
```## Primitives
* `Vec2(x: Double, y: Double)`
* `LineLine(start: Vec2, end: Vec2)`
* `Circle(center: Vec2, r: Double)`
* `AARect(center: Vec2, size: Vec2)` - Axis aligned rectangle
* `RotatedRect(center: Vec2, size: Vec2, angle: Double)` - Rotated rectangle
* `ConvexPolygon(verticesCCW: IndexedSeq[Vec2])` - Convex polygon with vertices in counter-clockwise order## Algorithms
* Point-Line distance
* Point-Line-Segment distance
* Project point on line
* Axis-aligned bounding-box for a set of vertices
* Line-Line intersection returning intersection points
* Line-ConvexPolygon intersection returning intersection points
* Circle-AARect intersection returning intersection points
* Circle-ConvexPolygon intersection test
* Circle-ConvexPolygon intersection returning MTD (Minimum Translation Distance) vector
* ConvexPolygon-ConvexPolygon intersection returning MTD (Minimum Translation Distance) vector
* Clamp Line by ConvexPolygon
* Convex Hull of Points