Transform

Transform

题目链接
题意 :
给你两点(A,B,C)和(x,y,z)在三维空间。设L是穿过点(A,B,C)和原点(0,0,0)的直线。如果你把点(x,y,z)绕线L旋转r度和-r度,你将得到两个点P和Q。如果P的z坐标大于Q,则输出P,否则输出Q,我们保证解决方案是唯一的。
思路 :
三维几何旋转向量模板
AC代码 :


#include <iostream>
#include <map>
#include <cstring>
#include <algorithm>
#include <math.h>

#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;

const int N = 5007, M = 50007, INF = 0x3f3f3f3f;
const double DINF = 1e18, eps = 1e-8, Pi = acos(-1.0);
inline double R_to_D(double rad) { return 180 / Pi * rad; } //弧度转角度
inline double D_to_R(double D) { return Pi / 180 * D; }		//角度转弧度

struct Point
{
	double x, y, z;
	Point(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {} //构造函数
};

typedef Point Vector;
Vector operator+(Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y, A.z + B.z); }
Vector operator-(Point A, Point B) { return Vector(A.x - B.x, A.y - B.y, A.z - B.z); }
Vector operator*(Vector A, double p) { return Vector(A.x * p, A.y * p, A.z * p); }
Vector operator/(Vector A, double p) { return Vector(A.x / p, A.y / p, A.z / p); }
bool operator<(const Point &a, const Point &b)
{
	if (a.x != b.x)
		return a.x < b.x;
	else if (a.y != b.y)
		return a.y < b.y;
	else
		return a.z < b.z;
}

double Dot(Vector A, Vector B) { return A.x * B.x + A.y * B.y + A.z * B.z; }

Vector multi(Vector A, Vector B) { return Vector(A.y * B.z - B.y * A.z, B.x * A.z - A.x * B.z, A.x * B.y - B.x * A.y); }

Vector To_UnitVector(Vector U)
{
	double k = sqrt(Dot(U, U));
	return Vector(U / k);
}

//罗德里格斯公式
//三维中点V绕着点U旋转r弧度,按照右手螺旋定则
Vector eval(Vector U, Vector V, double r)
{
	return V * cos(r) + U * Dot(U, V) * (1 - cos(r)) + multi(U, V) * sin(r);
}

int main()
{
	int T;
	IOS;
	while (~scanf("%d", &T))
	{
		while (T--)
		{
			double A, B, C, x, y, z, r;
			Vector U, V, P, Q;
			scanf("%lf %lf %lf %lf %lf %lf %lf", &A, &B, &C, &x, &y, &z, &r);
			U = {A, B, C};
			V = {x, y, z};
			U = To_UnitVector(U);
			P = eval(U, V, D_to_R(r));
			Q = eval(U, V, D_to_R(-r));
			if (P.z > Q.z)
				printf("%.8lf %.8lf %.8lf\n", P.x, P.y, P.z);
			else
				printf("%.8lf %.8lf %.8lf\n", Q.x, Q.y, Q.z);
		}
	}
	return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值