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 module

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)) -- Alias to Edge.new
     print(e) -- print the edge members p1 and p2
    
Edge:same (otherEdge)
Test if otherEdge is similar to self. It does not take into account the direction.

Parameters:

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)) --> true
     print(e1 == e2)) --> false, == operator considers the direction
    
Edge:length ()
Returns the length.

Returns:

    the length of self

Usage:

     local e = Edge(Point(), Point(10,0))
     print(e:length()) --> 10
    
Edge:getMidPoint ()
Returns the midpoint coordinates.

Returns:

  1. the x-coordinate of self midpoint
  2. the y-coordinate of self midpoint

Usage:

     local e = Edge(Point(), Point(10,0))
     print(e:getMidPoint()) --> 5, 0
    

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) -- Alias to Point.new
     print(p) -- print the point members x and y
    
Point:dist2 (p)
Returns the square distance to another Point .

Parameters:

Returns:

    the square distance from self to p.

Usage:

     local p1, p2 = Point(), Point(1,1)
     print(p1:dist2(p2)) --> 2
    
Point:dist (p)
Returns the distance to another Point .

Parameters:

Returns:

    the distance from self to p.

Usage:

     local p1, p2 = Point(), Point(1,1)
     print(p1:dist2(p2)) --> 1.4142135623731
    
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)) --> true
    

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) -- Alias to Triangle.new
     print(t) -- print the triangle members p1, p2 and p3
    
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()) --> true
    
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()) --> true
    
Triangle:getSidesLength ()
Returns the length of the edges

Returns:

  1. the length of the edge p1-p2
  2. the length of the edge p2-p3
  3. 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()) --> 2  1.4142135623731  1.4142135623731
    
Triangle:getCenter ()
Returns the coordinates of the center

Returns:

  1. the x-coordinate of the center
  2. 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()) --> 1 0.33333333333333
    
Triangle:getCircumCircle ()
Returns the coordinates of the circumcircle center and its radius

Returns:

  1. the x-coordinate of the circumcircle center
  2. the y-coordinate of the circumcircle center
  3. 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()) --> 1	0	1
    
Triangle:getCircumCenter ()
Returns the coordinates of the circumcircle center

Returns:

  1. the x-coordinate of the circumcircle center
  2. 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()) --> 1	0
    
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()) --> 1
    
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()) --> 1
    
Triangle:inCircumCircle (p)
Checks if a given point lies into the triangle circumcircle

Parameters:

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))) --> true
    

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 vargarg list 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
generated by LDoc 1.4.0