Delaunay module documentation (original) (raw)
Script delaunay
Delaunay, Lua module for convex polygon triangulation
Info:
- Copyright: 2013
- License: MIT
- Author: Roland Yonaba
Class Edge
| Edge:new (p1, p2) | Creates a new Edge |
|---|---|
| Edge:same (otherEdge) | Test if otherEdge is similar to self. |
| Edge:length () | Returns the length. |
| Edge:getMidPoint () | Returns the midpoint coordinates. |
Class Point
| Point:new (x, y) | Creates a new Point |
|---|---|
| Point:dist2 (p) | Returns the square distance to another Point . |
| Point:dist (p) | Returns the distance to another Point . |
| Point:isInCircle (cx, cy, r) | Checks if self lies into the bounds of a circle |
Class Triangle
| Triangle:new (p1, p2, p3) | Creates a new Triangle |
|---|---|
| Triangle:isCW () | Checks if the triangle is defined clockwise (sequence p1-p2-p3) |
| Triangle:isCCW () | Checks if the triangle is defined counter-clockwise (sequence p1-p2-p3) |
| Triangle:getSidesLength () | Returns the length of the edges |
| Triangle:getCenter () | Returns the coordinates of the center |
| Triangle:getCircumCircle () | Returns the coordinates of the circumcircle center and its radius |
| Triangle:getCircumCenter () | Returns the coordinates of the circumcircle center |
| Triangle:getCircumRadius () | Returns the radius of the circumcircle |
| Triangle:getArea () | Returns the area |
| Triangle:inCircumCircle (p) | Checks if a given point lies into the triangle circumcircle |
| Delaunay | Delaunay module |
|---|---|
| Delaunay.triangulate (...) | Triangulates a set of given vertices |
Class Edge
Edge:new (p1, p2)
Creates a new Edge
Parameters:
Returns:
a new Edge
Usage:
local Delaunay = require 'Delaunay' local Edge = Delaunay.Edge local Point = Delaunay.Point local e = Edge:new(Point(1,1), Point(2,5)) local e = Edge(Point(1,1), Point(2,5)) print(e)
Edge:same (otherEdge)
Test if otherEdge is similar to self. It does not take into account the direction.
Parameters:
- otherEdge an Edge
Returns:
true or false
Usage:
local e1 = Edge(Point(1,1), Point(2,5)) local e2 = Edge(Point(2,5), Point(1,1)) print(e1:same(e2)) print(e1 == e2))
Edge:length ()
Returns the length.
Returns:
the length of self
Usage:
local e = Edge(Point(), Point(10,0)) print(e:length())
Edge:getMidPoint ()
Returns the midpoint coordinates.
Returns:
- the x-coordinate of self midpoint
- the y-coordinate of self midpoint
Usage:
local e = Edge(Point(), Point(10,0)) print(e:getMidPoint())
Class Point
Point:new (x, y)
Creates a new Point
Parameters:
- x the x-coordinate
- y the y-coordinate
Returns:
a new Point
Usage:
local Delaunay = require 'Delaunay' local Point = Delaunay.Point local p = Point:new(1,1) local p = Point(1,1) print(p)
Point:dist2 (p)
Returns the square distance to another Point .
Parameters:
- p a Point
Returns:
the square distance from self to p.
Usage:
local p1, p2 = Point(), Point(1,1) print(p1:dist2(p2))
Point:dist (p)
Returns the distance to another Point .
Parameters:
- p a Point
Returns:
the distance from self to p.
Usage:
local p1, p2 = Point(), Point(1,1) print(p1:dist2(p2))
Point:isInCircle (cx, cy, r)
Checks if self lies into the bounds of a circle
Parameters:
- cx the x-coordinate of the circle center
- cy the y-coordinate of the circle center
- r the radius of the circle
Returns:
true or false
Usage:
local p = Point() print(p:isInCircle(0,0,1))
Class Triangle
Triangle:new (p1, p2, p3)
Creates a new Triangle
Parameters:
Returns:
a new Triangle
Usage:
local Delaunay = require 'Delaunay' local Triangle = Delaunay.Triangle local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle:new(p1, p2, p3) local t = Triangle(p1, p2, p3) print(t)
Triangle:isCW ()
Checks if the triangle is defined clockwise (sequence p1-p2-p3)
Returns:
true or false
Usage:
local p1, p2, p3 = Point(), Point(1,1), Point(2,0) local t = Triangle(p1, p2, p3) print(t:isCW())
Triangle:isCCW ()
Checks if the triangle is defined counter-clockwise (sequence p1-p2-p3)
Returns:
true or false
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:isCCW())
Triangle:getSidesLength ()
Returns the length of the edges
Returns:
- the length of the edge p1-p2
- the length of the edge p2-p3
- the length of the edge p3-p1
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:getSidesLength())
Triangle:getCenter ()
Returns the coordinates of the center
Returns:
- the x-coordinate of the center
- the y-coordinate of the center
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:getCenter())
Triangle:getCircumCircle ()
Returns the coordinates of the circumcircle center and its radius
Returns:
- the x-coordinate of the circumcircle center
- the y-coordinate of the circumcircle center
- the radius of the circumcircle
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:getCircumCircle())
Triangle:getCircumCenter ()
Returns the coordinates of the circumcircle center
Returns:
- the x-coordinate of the circumcircle center
- the y-coordinate of the circumcircle center
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:getCircumCenter())
Triangle:getCircumRadius ()
Returns the radius of the circumcircle
Returns:
the radius of the circumcircle
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:getCircumRadius())
Triangle:getArea ()
Returns the area
Returns:
the area
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:getArea())
Triangle:inCircumCircle (p)
Checks if a given point lies into the triangle circumcircle
Parameters:
- p a Point
Returns:
true or false
Usage:
local p1, p2, p3 = Point(), Point(2,0), Point(1,1) local t = Triangle(p1, p2, p3) print(t:inCircumCircle(Point(1,-1)))
Delaunay module
Delaunay
Delaunay module
Fields:
- Point reference to the Point class
- Edge reference to the Edge class
- Triangle reference to the Triangle class
- _VERSION the version of the current module
Delaunay.triangulate (...)
Triangulates a set of given vertices
Parameters:
- ... a
vargarglist of objects of type Point
Returns:
a set of objects of type Triangle
Usage:
local Delaunay = require 'Delaunay' local Point = Delaunay.Point local p1, p2, p3, p4 = Point(), Point(2,0), Point(1,1), Point(1,-1) local triangles = Delaunay.triangulate(p1, p2, p3, p4) for i = 1, #triangles do print(triangles[i]) end