CPolygon:new


The new method creates and returns a new CPolygon object.

Syntax

P = CPolygon:new()

P = CPolygon:new( CPolygonOld )

P = CPolygon:new( 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 CPolygon:new.

 

A = CPolygon:new()

-- create a CPolygon A

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

-- result: [0,0] = 0

 

 

B = CPolygon:new( 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 = CPolygon:new( 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

delete

CPolygon class

NewPolygon