Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, March 13, 2007

Matrix Transformation

Matrix takes three points as parameters, first point is the origin, the second point being the X-axis and third point marks the Y-axis. Changing the order of points changes the orientation of the XY-axis. The Transform function of Graphics associates the Matrix to the graphics object. The newly drawn graph objects would have the new orientation. The TranslateTransform function of Graphics object moves the origin to the new point that is passed as parameter to TranslateTransform.
 
private PointF[] pArray;

Matrix m;

Graphics g;

//Rectangle must be declared before usage.

//pArray is initialized here.

m = new Matrix(Rectangle, pArray);

g.Transform = m;


pArray = new PointF[] { new PointF(this.Width, this.Height), new PointF(0, 0), new PointF(0, this.Height) };

X diagonal
Y horizontal


pArray = new PointF[] { new PointF(0, this.Height), new PointF(this.Width, this.Height), new PointF(0, 0) };

X horizontal
Y vertical


pArray = new PointF[] { new PointF(this.Width, this.Height), new PointF(0, this.Height), new PointF(0, 0) };

X horizontal
Y diagonal


pArray = new PointF[] { new PointF(0, 0), new PointF(0, this.Height), new PointF(this.Width, this.Height) };

X vertical
Y diagonal


pArray = new PointF[] { new PointF(0, 0), new PointF(this.Width, this.Height), new PointF(0, this.Height) };

X diagonal
Y vertical


pArray = new PointF[] { new PointF(0, this.Height), new PointF(0, 0), new PointF(this.Width, this.Height) };

X horizontal
Y vertical

Monday, March 05, 2007

In the Matrix of Arrays and RectangleF

My brain is being beaten like a drum with sticks
Oh it's driving me crazy! this concept of Matrix
How do I draw graphs and points using graphics?
Entire client area seems confused with my clicks
Google hasn't been of help in finding any quick fix
Those developers seem like they are in politics
It seems I am unable to create an array of points six
Where oh where is a wall so I can band my head on bricks?


March 05, 2007

Friday, February 23, 2007

Ay...ay...ay...ay...ay... Indexers!

Indexers provide array-like access to any objects. Here's an example that demonstrates how to use them:

class myIndexerGeneric
{
private T[] indxr = new T[10];
public T this[int i]
{
get { return indxr[i]; }
set { indxr[i] = value; }
}
}


private void TestIndexer()
{
ArrayList a = new ArrayList();
a.Add("TextIn");

myIndexerGeneric<ArrayList> g = new myIndexerGeneric<ArrayList>();
g[0] = a;

ArrayList b = new ArrayList();
b = g[0];
}

Sunday, February 18, 2007

Arrays vs ArrayLists in C#

Initially, I had a very hard time understanding the concept of Arrays vs. ArrayLists. So finally after browsing and searching on google and four textbooks for an explanation that makes sense, I put together these lists:

Arrays
- Require a counter for accessing elements
- Need to use ReDim Preserve
- Type specific - data types must be same throughout the array
- Homogeneous data - same data type

ArrayLists
- Do not require a counter
- No need to use ReDim Preserve
- Items can be removed
- Items can be sorted
- Items can be searched
- Items can be added at runtime
- Items can be replaced
- Can hold objects (custom or defined) and it is possible to have more than one data type objects in one arraylist
- Heterogeneous data - data type can differ from object to object
- Is a DataStructure in .NET
- Its capacity is increased if required as objects are added to it. So it frees programmer from the worries of array overflow.
- Can be made read only after adding elements to prevent unintentional modifications.
- Provides an overloaded method to perform binary search on Its objects.
- Implements IList interface using an array.