triangle_sym.lua


NAME
    triangle_sym

FUNCTION
    triangle_sym(plot, width, height, arr, size)

NOTES
    Adds triangle symbols to the plot.

INPUTS
    plot   - zePlot object
    width  - image width
    height - image height
    arr    - zeArray object having 2 vectors  containing data of x and y
    size   - symbol size in pixels

OUTPUTS
    a polygon object of GL_TRIANGLES

SOURCE

require("register")

function triangle_sym(plot, width, height, arr, size)
    local shape, xyz = zeGrf.new("polygon", "vertex")
    plot:add(shape)
    shape:set{vertex = xyz, type = "triangles"}
    local n = arr:size()
    local x, y = plot:toplot(width, height, 0, 0, 0)
    local dx, dy = plot:toplot(width, height, 0.5 * size, 0.5 * size, 0)
    dx = dx - x
    dy = dy - y
    for i = 1, n do
        local x = arr:getele(i-1, 0)
        local y = arr:getele(i-1, 1)
        xyz:add(x - dx, y - dy, 0) 
        xyz:add(x + dx, y - dy, 0) 
        xyz:add(x, y + dy, 0) 
    end
    return shape
end