When working with the component we often need to use math. To facilitate the work, the component includes a set of supporting classes. Let’s review some of them:

## Vector2D

Vector2D is one of the main classes that represents a point on the plane. It includes implicit methods intended for converting between Vector2D and Point and Size classes in Silverlight. The main operations (+, -, *, /) here are overloaded and there are many useful manipulations with vectors. The main ones include:

**Angle **– vectorial angle
**Length** – vector length

**DotProduct**(Vector2D, Vector2D)
**CrossProduct**(Vector2D, Vector2D)
**GetProjection**(start, end) – gets the projection on a line
**FromPolar**(length, angle) – builds a vector by polar coordinates
**GetNormalized**() – gets a unit vector with the same vectorial angle
**Rotate**(angle)
**RotateAt**(pivot, angle)
**Parse**(string, IFormatProvider)
**ToString**()

## Rectangle2D

Rectangle2D – one of the main classes that represents a rectangle on the plane with the sides parallel to axis of coordinates. There are implicit methods intended for converting between the Rectangle2D and the Rect class in Silverlight. The &, |, *, / (transverse and integrating, multiplication and division) operations are redefined. Among other properties and methods one can point out the following:

*Location*, *Size *– properties to set a rectangle
*Top*, *Bottom*, *Left*, *Right*, *CenterX*, *CenterY *– get rectangle borders
- TopLeft,
*BottomLeft*, *TopRight*, *BottomRight*, *TopCenter*, *BottomCenter*, *LeftCenter*, *RightCenter*, *Center *– main points of a rectangle
*Square *– rectangle square

*Contains*( Vector2D), Contains(Rectangle2D) – check if the objects belong to the rectangle area
*UnionAll*(IEnumerable) – unites a set of rectangles
*BuildByPoints*(Vector2D[]) – builds a rectangle with minimum square to cover all defined points.

## MathUtilities

*
MathUtilities *– is a small class that represents a set of static mathematical methods. It allows calculating determinants, get the

*Max*() and

*Min*() functions from 3 and 4 X arguments, get the

*Clamp* function which corrects a number putting it into the defined interval (

*Clamp*(x, a, b) =

*Max*(a,

*Min*(b, x))).

## GeometryUtilities

*
GeometryUtilities *– is a class that represents various static methods to work with geometric objects including conversion between degrees and radians, calculation of specific angles, operations with right lines (distance from a point to a right line, checking of lines for parallelism, point display by axis of symmetry, etc), methods to work with Bezier curves and ellipses.

## AffineTransform

*
AffineTransform *– is a very useful class that represents affine transformation. Its main destinations are:

- To enable transformation for a shape (
*Move*, *Rotate*, *Scale*, etc), it should implement the *ApplyAffineTransform*() method. Inside that method, a shape decides how to be transformed if the corresponding action is taken to it. Thanks to such approach it is possible to apply virtually any geometric operations with an object.
- The
*IDrawingContext* has the *PushAffineTransform* method. It allows override further drawing of geometric primitives applying the corresponding transformation. It is often used for transformations of coordinate system.
- The
* CreateByPoints*(p1, p2, p3, q1, q2, q3) and the *CreateInverse* methods are the most useful for local geometrical design. The first one builds the AffineTransform by 3 starting points and by 3 shapes into which they should be transformed. And the *CreateInverse* allows building reverse affine transformation.

Article ID: 431, Created: March 6, 2012 at 1:57 PM, Modified: March 6, 2012 at 1:57 PM