Package fuzzy :: Package set :: Module Polygon :: Class Polygon
[hide private]
[frames] | no frames]

Class Polygon

source code


Represents a fuzzy set, which membership function is the shape of a polygon. For example: triangle, trapezoid, rectangle, or something similar.

If you need something similar to ZFunction or SFunction, use this class directly by building it from two points.:

  ---*                     *---
      \                   /
       \        OR       /
        \               /
         *---       ---*

See also http://pyfuzzy.sourceforge.net/demo/set/Polygon%20(Demo).png

Instance Methods [hide private]
 
__init__(self, points=None)
Initialize with given sorted list of (x,y) values
source code
float
__call__(self, x)
Get membership of value x.
source code
 
add(self, x, y, where=1)
Add a new point to the polygon.
source code
 
remove(self, x, where=1)
Remove a point from the polygon.
source code
 
clear(self)
Reset polygon to zero.
source code
 
getValuesX(self)
Return sequence of x-values for set.
source code
 
getValuesXY(self, flat=True)
Return sequence of (x,y)-values for set.
source code
float
getCOG(self)
Return center of gravity.
source code
string
__repr__(self)
Return representation of instance.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  X = 0
index of x value in tuple
  Y = 1
index of y value in tuple
  BEGIN = 0
  END = 1
Properties [hide private]
list of 2-tuple (x,y) points
points of the polygon.

Inherited from object: __class__

Method Details [hide private]

__init__(self, points=None)
(Constructor)

source code 

Initialize with given sorted list of (x,y) values

Parameters:
  • points (list of 2-tuples (float,float)) - sorted list of 2-tuples of (x,y) values
Overrides: object.__init__

__call__(self, x)
(Call operator)

source code 

Get membership of value x.

Parameters:
  • x - value x
Returns: float
membership for value x
Overrides: Set.Set.__call__

add(self, x, y, where=1)

source code 

Add a new point to the polygon. The parameter where controls at which end it is inserted. (The points are always sorted, but if two have the same x value their order is important. For example: adding a second point(y=0) in the middle:

now           where=END        where=BEGIN
*--*           *--*             *  *
    \             |              \ |\
     \            |               \| \
      *           *--*             *  *

remove(self, x, where=1)

source code 

Remove a point from the polygon. The parameter where controls at which end it is removed. (The points are always sorted, but if two have the same x value their order is important. For example: removing the second point in the middle:

now           where=END        where=BEGIN
*--*           *--*             *
   |               \             \
   |                \             \
   *--*              *             *--*

getValuesX(self)

source code 

Return sequence of x-values for set.

Overrides: Set.Set.getValuesX

getValuesXY(self, flat=True)

source code 

Return sequence of (x,y)-values for set. In case of vertical slopes, y is a tuple of y-values for flat = False. Otherwise several (x,y)-values will be generated having identical x-values.

Overrides: Set.Set.getValuesXY

getCOG(self)

source code 

Return center of gravity.

Returns: float
x-value of center of gravity
Overrides: Set.Set.getCOG

__repr__(self)
(Representation operator)

source code 

Return representation of instance.

Returns: string
representation of instance
Overrides: object.__repr__

Property Details [hide private]

points

points of the polygon.

Get Method:
unreachable.fget(self)
Type:
list of 2-tuple (x,y)