Hello.
Entities on drawing can be conditionally sorted on two groups. The first group includes entities defined by points/vertexes, for example CADLine, CADPolyLine and CADSpline. Other entities, like CADText, CADInsert or CADImageEnt defined by insertion point and other properties.
CADMatrix class can be used to apply transformations to a single entity. For the entities from the first group each point/entity must be multiplied by matrix object. Entities from second group provide different properties like Scale or Angle to transform. The insertion point can be affected by matrix.
The following example shows scaling and rotation of a line. Rotation can be completed also around any other point.
- Code: Select all
{
CADLine line = (CADLine)cadImage.Converter.Entities[0];
// scale
CADMatrix matrix = new CADMatrix();
double scaleX = 2.0;
double scaleY = 1.5;
double scaleZ = 3.4;
matrix[0, 0] = scaleX;
matrix[1, 1] = scaleY;
matrix[2, 2] = scaleZ;
line.Point = PointXmat(line.Point, matrix);
line.Point1 = PointXmat(line.Point1, matrix);
cadImage.Converter.Loads(line);
//end of scale
//rotate around (0, 0)
CADMatrix matrix = new CADMatrix();
double angle = 15;
matrix[0, 0] = Math.Cos(Math.PI * angle / 180);
matrix[0, 1] = Math.Sin(Math.PI * angle / 180);
matrix[1, 0] = -matrix[0, 1];
matrix[1, 1] = matrix[0, 0];
line.Point = PointXmat(line.Point, matrix);
line.Point1 = PointXmat(line.Point1, matrix);
cadImage.Converter.Loads(line);
//end of rotation
}
private DPoint PointXmat(DPoint pt, CADMatrix mat)
{
DPoint result;
result.X = pt.X * mat[0, 0] + pt.Y * mat[1, 0] + pt.Z * mat[2, 0] + mat[3, 0];
result.Y = pt.X * mat[0, 1] + pt.Y * mat[1, 1] + pt.Z * mat[2, 1] + mat[3, 1];
result.Z = pt.X * mat[0, 2] + pt.Y * mat[1, 2] + pt.Z * mat[2, 2] + mat[3, 2];
return result;
}
Unfortunately translation of an entity isn't clear to us. Please specify what did you mean by this term.
Alexander.