sgu265:Wizards(计算几何)
来源:互联网 发布:六边形战士 知乎 编辑:程序博客网 时间:2024/04/30 18:33
题目大意:
分析:
分析:
#include <cstdio>#include <cmath>typedef double DB;using namespace std;const DB PI = acos(-1.0);const DB eps = 1e-10;struct pot{ DB x, y, z; pot(DB x = 0, DB y = 0, DB z = 0):x(x),y(y),z(z){} void read() {scanf("%lf%lf%lf", &x, &y, &z);} void print() {printf("%lf %lf %lf\n", x, y, z);} void trans(DB tx, DB ty, DB tz) {x += tx, y += ty, z += tz;} void scal(DB tx, DB ty, DB tz) {x *= tx, y *= ty, z *= tz;} void rotate(const pot &a, DB alpha) { pot p = *this, tmp; tmp = a*((a*p)/(a*a)); p = p-tmp;pot m = a^p; if(m.len() < eps) return ; m.adjust(p.len()); *this = p*cos(alpha)+m*sin(alpha)+tmp; } friend pot operator + (const pot &a, const pot &b) {return pot(a.x+b.x, a.y+b.y, a.z+b.z);} friend pot operator - (const pot &a, const pot &b) {return pot(a.x-b.x, a.y-b.y, a.z-b.z);} friend pot operator * (const pot &a, DB k) {return pot(a.x*k, a.y*k, a.z*k);} friend pot operator / (const pot &a, DB k) {return pot(a.x/k, a.y/k, a.z/k);} friend DB operator * (const pot &a, const pot &b) {return a.x*b.x+a.y*b.y+a.z*b.z;} friend pot operator ^ (const pot &a, const pot &b) {return pot(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x);} DB len() {return sqrt((*this)*(*this));} void adjust(DB l) {*this = *this*(l/len());}}p[4], v;int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, m; scanf("%d", &n); p[1].x = p[2].y = p[3].z = 1; while(n--) { DB x, y, z, a; char q[3] = "\0"; scanf("%s", q); scanf("%lf%lf%lf", &x, &y, &z); if(q[0] == 'T') p[0].trans(x, y, z); else if(q[0] == 'S') for(int i = 0; i < 4; ++i) p[i].scal(x, y, z); else { scanf("%lf", &a);a *= PI/180; for(int i = 0; i < 4; ++i) p[i].rotate(pot(x, y, z), a); } } scanf("%d", &m); while(m--) { v.read(); v = p[0]+p[1]*v.x+p[2]*v.y+p[3]*v.z; v.print(); } #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0;}
0 0
- sgu265:Wizards(计算几何)
- 计算几何几何函数库
- 计算几何-几何库
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- 计算几何
- Linux 进程间通信
- Lifetime Improvement of NAND Flash-based Storage Systems Using Dynamic Program and Erase Scaling
- 【高级算法】Lasvegas算法解决3SAT问题(C++实现代码)
- 无限级分类展示
- 生成树(treegrid)的数据格式
- sgu265:Wizards(计算几何)
- 日志框架实现实时修改,实时生效,具体框架思路(1)
- 二维DCT变换
- Android网络编程之传递数据给服务器
- 细说linux性能优化
- JVM的gc概述
- c++ & * 符号的多重含义
- quick3x_游戏场景计时器
- Java中字符串比较时==和equals的区别