.NET

Reply
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 1 of 9 (148 Views)

Scale and Matrix

148 Views, 8 Replies
06-02-2005 11:33 PM
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
Active Contributor
tangferry
Posts: 43
Registered: ‎04-21-2005
Message 2 of 9 (148 Views)

Re: Scale and Matrix

06-03-2005 12:15 AM in reply to: RolandF
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);
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 3 of 9 (148 Views)

Re: Scale and Matrix

06-03-2005 12:26 AM in reply to: RolandF
Sorry for that question, but i couldn't find it.
Thank you.

Roland
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 4 of 9 (148 Views)

Re: Scale and Matrix

07-11-2005 07:07 AM in reply to: RolandF
if xcale and yscale isn't same ,how to scale a entity.
*Albert Szilvasy
Message 5 of 9 (148 Views)

Re: Scale and Matrix

07-14-2005 08:42 AM in reply to: RolandF
Call Entity.GetTransformedCopy.

Albert
wrote in message news:4897704@discussion.autodesk.com...
if xcale and yscale isn't same ,how to scale a entity.
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 6 of 9 (148 Views)

Re: Scale and Matrix

07-15-2005 12:25 AM in reply to: RolandF
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.
*Albert Szilvasy
Message 7 of 9 (148 Views)

Re: Scale and Matrix

07-15-2005 08:38 AM in reply to: RolandF
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.
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 8 of 9 (148 Views)

Re: Scale and Matrix

07-15-2005 11:10 PM in reply to: RolandF
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;

}
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 9 of 9 (148 Views)

Re: Scale and Matrix

07-15-2005 11:11 PM in reply to: RolandF
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;

}
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!