已知矩形中心点坐标、长、宽、角度,求角点坐标

	vector arrPtRect;
    point2d ptMid(0,0); //中心点坐标
    double dLength = 200; //长
    double dWidth = 200; //宽
    double dAngle = ...; //弧度

	double y1 = ptMid.X() + dWidth / 2 * sin(dAngle);
	double x1 = ptMid.Y() - dWidth / 2 * cos(dAngle);
	double y2 = ptMid.X() - dWidth / 2 * sin(dAngle);
	double x2 = ptMid.Y() + dWidth / 2 * cos(dAngle);

	//左上角点
	point2d ptTopLeft;
	ptTopLeft.X() = y2 - dLength / 2 * cos(dAngle);
	ptTopLeft.Y() = x2 - dLength / 2 * sin(dAngle);

	//左下角点
	point2d ptBottomLeft;
	ptBottomLeft.X() = y1 - dLength / 2 * cos(dAngle);
	ptBottomLeft.Y() = x1 - dLength / 2 * sin(dAngle);

	//右下角点
	point2d  ptBottomRight;
	ptBottomRight.X() = y1 + dLength / 2 * cos(dAngle);
	ptBottomRight.Y() = x1 + dLength  / 2 * sin(dAngle);

	//右上角点
	point2d ptTopRight;
	ptTopRight.X() = y2 + dLength / 2 * cos(dAngle);
	ptTopRight.Y() = x2 + dLength / 2 * sin(dAngle);
	arrPtRect.emplace_back(ptTopLeft);
	arrPtRect.emplace_back(ptBottomLeft);
	arrPtRect.emplace_back(ptBottomRight);
	arrPtRect.emplace_back(ptTopRight);

你可能感兴趣的:(算法,c++)