NewPolygon


The NewPolygon function creates and returns a new CPolygon object. This function is a global form of the CPolygon:new method.

Syntax

P = NewPolygon()

P = NewPolygon( CPolygonOld )

P = NewPolygon( arrayX, arrayY )

where

    The first form, with no arguments, creates a default CPolygon object with default properties.

    CPolygonOld is an existing CPolygon object. This form creates a new CPolygon object initialized to the properties of CPolygonOld.

    arrayX, arrayY are two lua arrays containing, respectively, the x values and y values to be used for the polygon points.

    P is a new CPolygon object.

Example

The following script illustrates using various forms of NewPolygon.

 

A = NewPolygon()

-- create a CPolygon A

Printf("[%d,%d] = %d", A.xc, A.yc, A:Count() )

-- result: [0,0] = 0

 

 

B = NewPolygon( A )

-- copy CPolygon A to a new CPolygon B

B.xc = 2.5 ; B.yc = -2.1

-- specify the center values

Printf("[%d,%d] = %d", B.xc, B.yc, B:Count() )

-- result: [2.5,-2.1] = 0

 

 

x = {4,5,6,7} ; y = {1,2,-3,5}

-- create some x and y data

C = NewPolygon( x, y )

-- create a CPolygon C from arrays

x0,y0 = C:CalcCenter()

-- calculate the center of mass

Printf("[%d,%d] = %d", x0, y0, C:Count() )

-- result: [5.5,-1.25] = 4

 

 

Related Topics

new

delete

CPolygon class