图形自定义方向拉伸

Posted on 2016-12-15 13:38  云起  阅读(18)  评论(0)    收藏  举报  来源

对一个二维图形,指定两个垂直方向,依照不同比例进行拉伸。如图


对某一节点到指定基点向量计算推演等式


以基点为原点,将目标坐标系顺时针旋转至直角系,然后进行xy轴向拉伸,再逆时针旋转回去

示例代码(以0、1两点方向为基准方向,0为基准点)

private IGeometry Scale(IGeometry ig)
{
	IPointCollection pc = ig as IPointCollection;
	IPoint bpt = gc.get_Point(0);
	IPoint npt = gc.get_Point(1);
	double angle = Math.Atan2(bpt.Y - npt.Y , bpt.X - npt.X);
	double xff = 2 , yff = 3;//拉伸系数

	IPointCollection tf = new PolygonClass();
	double p1 = xff * Math.Cos(angle) * Math.Cos(angle) + yff * Math.Sin(angle) * Math.Sin(angle);
	double p2 = (xff - yff) * Math.Cos(angle) * Math.Sin(angle) , p3 = p2;
	double p4 = xff * Math. Sin(angle) * Math. Sin(angle) + yff * Math. Cos(angle) * Math. Cos(angle);
	For(int i = 0;i<pc.Pointcount;i + + )
	{
		IPoint curPt = pc.get_Point(i);
		double x = curPt.X - bpt.X;
		double y = curPt.Y - bpt.Y;
		double dx = x * p1 + y * p3;
		double dy = x * p2 + y * p4;
		tf.AddPoint(new PointClass(){X = bpt.X + dx , Y = bpt.Y + dy});
        }
        return tf as IGeometry;
}



博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3