.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Scale and Matrix

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
690 Views, 8 Replies

Scale and Matrix

In 2005 it was possible to set the scale-matix like this -->
[code] Point3d Obj1Punkt= new Point3d(50, 50, 100);
Point3d Obj2Punkt= new Point3d(10, 80, 300);

Line Boeschungslinie = new Line(Obj1Punkt, Obj2Punkt);

double Length = 20;

Matrix3d xScale = new Matrix3d();
xScale.SetToScaling(Length, Obj1Punkt);
Boeschungslinie.TransformBy(xScale);[/code]

but how can i do it now?

Roland
8 REPLIES 8
Message 2 of 9
tangferry
in reply to: Anonymous

You can do like the followings:

Point3d Obj1Punkt= new Point3d(50, 50, 100);
Point3d Obj2Punkt= new Point3d(10, 80, 300);
Line Boeschungslinie = new Line(Obj1Punkt, Obj2Punkt);
double Length = 20;
Matrix3d scaleMatrix=Matrix3d.Scaling(Length,Obj1Punkt);
Boeschungslinie.TransformBy(scaleMatrix);
Message 3 of 9
Anonymous
in reply to: Anonymous

Sorry for that question, but i couldn't find it.
Thank you.

Roland
Message 4 of 9
netcai
in reply to: Anonymous

if xcale and yscale isn't same ,how to scale a entity.
Message 5 of 9
Anonymous
in reply to: Anonymous

Call Entity.GetTransformedCopy.

Albert
wrote in message news:4897704@discussion.autodesk.com...
if xcale and yscale isn't same ,how to scale a entity.
Message 6 of 9
netcai
in reply to: Anonymous

could you explain it in detail. I can only use nonuniform matrix on block or point, if use it on other entity ,a error will appear.
Message 7 of 9
Anonymous
in reply to: Anonymous

Not all objects support non-uniform scaling. What objects did you try that
failed?

Albert
wrote in message news:4902374@discussion.autodesk.com...
could you explain it in detail. I can only use nonuniform matrix on block
or point, if use it on other entity ,a error will appear.
Message 8 of 9
netcai
in reply to: Anonymous

a polyline . I have found a solution , that is transform each point in the polyline and create a new polyline. but what cnfuse me is that direrent order of transform cause different result.


Entity subEnt = trans.GetObject(id, OpenMode.ForRead) as Entity;
if (subEnt is Polyline)
{
Polyline tempPoly = subEnt as Polyline;

double rot = br.Rotation;
double xscale = br.ScaleFactors.X;
double yscale = br.ScaleFactors.Y;
double zscale = br.ScaleFactors.Z;


//// method 1 scale, rotate and move
double[] dd = new double[16];
dd[0] = xscale;
dd[5] = yscale;
dd[10] = zscale;
dd[15] = 1;
Matrix3d scaleMatrix = new Matrix3d(dd);
Polyline tp = new Polyline();
for (int i = 0; i < tempPoly.NumberOfVertices; i++)
{
Point3d p3 = tempPoly.GetPoint3dAt(i).TransformBy(scaleMatrix);
Point2d p2 = new Point2d(p3.X, p3.Y);
tp.AddVertexAt(i, p2, tempPoly.GetBulgeAt(i), tempPoly.GetStartWidthAt(i), tempPoly.GetEndWidthAt(i));
}
tempPoly = tp;

Matrix3d m3dRot = Matrix3d.Rotation(rot, new Vector3d(0, 0, 1), Point3d.Origin);
tempPoly.TransformBy(m3dRot);

Matrix3d m3dDisp = Matrix3d.Displacement(insertPnt.GetAsVector());
tempPoly.TransformBy(m3dDisp);


//// method 2: move, rotate and scale

//Matrix3d m3dDisp = Matrix3d.Displacement(insertPnt.GetAsVector());
//tempPolyline.TransformBy(m3dDisp);

//Matrix3d m3dRot = Matrix3d.Rotation(rot, new Vector3d(0, 0, 1), insertPnt);
//tempPolyline.TransformBy(m3dRot);


//double[] dd = new double[16];
//dd[0] = xscale;
//dd[3] = insertPnt.X * (1 - xscale);
//dd[5] = yscale;
//dd[7] = insertPnt.Y * (1 - yscale);
//dd[10] = zscale;
//dd[15] = 1;
//Matrix3d scaleMatrix = new Matrix3d(dd);
//Polyline tp = new Polyline();
//for (int i = 0; i < tempPolyline.NumberOfVertices; i++)
//{
// Point3d p3 = tempPolyline.GetPoint3dAt(i).TransformBy(scaleMatrix);
// Point2d p2 = new Point2d(p3.X, p3.Y);
// tp.AddVertexAt(i, p2, tempPolyline.GetBulgeAt(i), tempPolyline.GetStartWidthAt(i), tempPolyline.GetEndWidthAt(i));
//}
//tempPolyline = tp;

}
Message 9 of 9
netcai
in reply to: Anonymous

a polyline . I have found a solution , that is transform each point in the polyline and create a new polyline. but what cnfuse me is that direrent order of transform cause different result.


Entity subEnt = trans.GetObject(id, OpenMode.ForRead) as Entity;
if (subEnt is Polyline)
{
Polyline tempPoly = subEnt as Polyline;

double rot = br.Rotation;
double xscale = br.ScaleFactors.X;
double yscale = br.ScaleFactors.Y;
double zscale = br.ScaleFactors.Z;


//// method 1 scale, rotate and move
double[] dd = new double[16];
dd[0] = xscale;
dd[5] = yscale;
dd[10] = zscale;
dd[15] = 1;
Matrix3d scaleMatrix = new Matrix3d(dd);
Polyline tp = new Polyline();
for (int i = 0; i < tempPoly.NumberOfVertices; i++)
{
Point3d p3 = tempPoly.GetPoint3dAt(i).TransformBy(scaleMatrix);
Point2d p2 = new Point2d(p3.X, p3.Y);
tp.AddVertexAt(i, p2, tempPoly.GetBulgeAt(i), tempPoly.GetStartWidthAt(i), tempPoly.GetEndWidthAt(i));
}
tempPoly = tp;

Matrix3d m3dRot = Matrix3d.Rotation(rot, new Vector3d(0, 0, 1), Point3d.Origin);
tempPoly.TransformBy(m3dRot);

Matrix3d m3dDisp = Matrix3d.Displacement(insertPnt.GetAsVector());
tempPoly.TransformBy(m3dDisp);


//// method 2: move, rotate and scale

//Matrix3d m3dDisp = Matrix3d.Displacement(insertPnt.GetAsVector());
//tempPolyline.TransformBy(m3dDisp);

//Matrix3d m3dRot = Matrix3d.Rotation(rot, new Vector3d(0, 0, 1), insertPnt);
//tempPolyline.TransformBy(m3dRot);


//double[] dd = new double[16];
//dd[0] = xscale;
//dd[3] = insertPnt.X * (1 - xscale);
//dd[5] = yscale;
//dd[7] = insertPnt.Y * (1 - yscale);
//dd[10] = zscale;
//dd[15] = 1;
//Matrix3d scaleMatrix = new Matrix3d(dd);
//Polyline tp = new Polyline();
//for (int i = 0; i < tempPolyline.NumberOfVertices; i++)
//{
// Point3d p3 = tempPolyline.GetPoint3dAt(i).TransformBy(scaleMatrix);
// Point2d p2 = new Point2d(p3.X, p3.Y);
// tp.AddVertexAt(i, p2, tempPolyline.GetBulgeAt(i), tempPolyline.GetStartWidthAt(i), tempPolyline.GetEndWidthAt(i));
//}
//tempPolyline = tp;

}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost