### Author Topic: Non-uniformly scaled Matrix3d  (Read 2532 times)

0 Members and 1 Guest are viewing this topic.

#### zoltan

• Newt
• Posts: 188
##### Non-uniformly scaled Matrix3d
« on: June 22, 2011, 08:58:21 AM »
For some reason, the Autodesk.AutoCAD.Geometry.Matrix3d struct does not have any methods to non-uniformly scale the axes.  It only provides a Scaling(double scaleAll, Point3d center) method to create a uniform scaleing matrix.  So I created a method to get back a non-uniform scaling matrix and use it for point transformations, but something is not right.

Code: [Select]
`        public static Matrix3d ScaleMatrix(double xScale, double yScale, double zScale, Point3d origin)        {            return Matrix3d.Identity                           .PostMultiplyBy(Matrix3d.Displacement(origin.GetAsVector().Negate()))                           .PostMultiplyBy(new Matrix3d(new double[] { xScale, 0.0, 0.0, 0.0,                                                                       0.0, yScale, 0.0, 0.0,                                                                       0.0, 0.0, zScale, 0.0,                                                                       0.0, 0.0, 0.0, 1.0 }))                           .PostMultiplyBy(Matrix3d.Displacement(origin.GetAsVector()));        }        public static Matrix3d ScaleMatrix(Scale3d scaling, Point3d origin)        {            return ScaleMatrix(scaling.X, scaling.Y, scaling.Z, origin);        }        public static Point3d Transform(this Point3d point, Point3d displacement, Scale3d scaling, double rotation)        {            Matrix3d transform = Matrix3d.Identity                                         .PostMultiplyBy(ScaleMatrix(scaling, Point3d.Origin))                                         .PostMultiplyBy(Matrix3d.Rotation(rotation, Vector3d.ZAxis, Point3d.Origin))                                         .PostMultiplyBy(Matrix3d.Displacement(displacement.GetAsVector()));            return point.TransformBy(transform);        }`
What have I done wrong?
« Last Edit: June 22, 2011, 09:02:56 AM by zoltan »

#### Bryco

• Water Moccasin
• Posts: 1864
##### Re: Non-uniformly scaled Matrix3d
« Reply #1 on: June 23, 2011, 08:55:46 PM »
public static Matrix3d scaleMatrix(double x,double y,double z,Point3d cen)
{
if (x == y && x == z) return Matrix3d.Scaling(x, cen);
double[] data={x,0,0,cen.X,0,y,0,cen.Y,0,0,z,cen.Z,0,0,0,1};
Matrix3d m = new Matrix3d(data);
return m;
}
Perhaps this is better. It looks like you are scaling the number zero

#### WizzApp

• Guest
##### Re: Non-uniformly scaled Matrix3d
« Reply #2 on: June 27, 2011, 06:34:52 AM »
I encountered the same problem last week, when I was trying to scale a BlockReference with different scaling factors.
I also build my own matrix, but scaling an entity is only allowed with uniformed scale factors.

However, if you want to scale a BlockReference with different scale factors you should try this:

Code: [Select]
`' Scale the blockreference' We can't use TransformBy in this case, because we might have different scaling factors here.Dim br as BlockReferencebr.ScaleFactors = New Scale3d(xScale, yScale, zScale)`