[하 얼 빈 온라인 콘테스트 2010][큐 빅 회전][3 차원 좌표 회전]
34724 단어 online
/*
:Cubic Rotation
:Harbin Online Contest 2010
http://acm.hrbeu.edu.cn/index.php?act=problem&id=1006&cid=16
:
:
http://dumbear.com/blog/?p=143
Sample ,Sample Input Sample “275” “270”
:2011.2.26
*/
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <bitset>
#include <cmath>
#include <set>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
struct cpoint {
double x, y;
cpoint(double xx = 0, double yy = 0): x(xx), y(yy) {}
};
int dcmp(double x) {
if (x < -eps) return -1; else return x > eps;
}
double cross(cpoint p0, cpoint p1, cpoint p2) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
int PointEqual(cpoint a, cpoint b) {
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double sqr(double x) { return x * x; }
double dissqr(cpoint a, cpoint b) {
return sqr(a.x - b.x) + sqr(a.y - b.y);
}
cpoint bp;
int PolarCmp(const cpoint &p1, const cpoint &p2) {
int u = dcmp(cross(bp, p1, p2));
return u > 0 || (u == 0 && dcmp(dissqr(bp, p1) - dissqr(bp, p2)) < 0);
}
void graham(cpoint pin[], int n, cpoint ch[], int &m) {
int i, j, k, u, v;
memcpy(ch, pin, n * sizeof(cpoint));
for (i = k = 0; i < n; ++i) {
u = dcmp(ch[i].x - ch[k].x);
v = dcmp(ch[i].y - ch[k].y);
if (v < 0 || (v == 0 && u < 0)) k = i;
}
bp = ch[k];
sort(ch, ch + n, PolarCmp);
n = unique(ch, ch + n, PointEqual) - ch;
if (n <= 1) { m = n; return ;}
if (dcmp(cross(ch[0], ch[1], ch[n - 1])) == 0) {
m = 2; ch[1] = ch[n - 1]; return;
}
ch[n++] = ch[0];
for (i = 1, j = 2; j < n; ++j) {
while (i > 0 && dcmp(cross(ch[i - 1], ch[i], ch[j])) <= 0) i--;
ch[++i] = ch[j];
}
m = i;
}
double PolygonArea(cpoint p[], int n) {
if (n < 3) return 0;
double s = p[0].y * (p[n - 1].x - p[1].x);
for (int i = 1; i < n; ++i)
s += p[i].y * (p[i - 1].x - p[(i + 1) % n].x);
return fabs(s / 2);
}
struct vpoint {
double x, y, z;
vpoint(double xx = 0, double yy = 0, double zz = 0)
: x(xx), y(yy), z(zz) {}
};
double dis(vpoint a, vpoint b) {
return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z));
}
// a p0p1 ( )
vpoint rotate(vpoint a, vpoint p0, vpoint p1, double angle) {
double d, s, c, x, y, z, x1, y1, z1;
d = dis(p0, p1); s = sin(angle); c = cos(angle);
x = (p1.x - p0.x) / d; x1 = a.x - p0.x;
y = (p1.y - p0.y) / d; y1 = a.y - p0.y;
z = (p1.z - p0.z) / d; z1 = a.z - p0.z;
p0.x += x1*(c+x*x*(1-c)) + y1*(x*y*(1-c)-z*s) + z1*(x*z*(1-c)+y*s);
p0.y += y1*(c+y*y*(1-c)) + z1*(y*z*(1-c)-x*s) + x1*(y*x*(1-c)+z*s);
p0.z += z1*(c+z*z*(1-c)) + x1*(z*x*(1-c)-y*s) + y1*(z*y*(1-c)+x*s);
return p0;
}
int dir[8][3] = {
{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1},
{0, 1, 1}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}
};
void solve() {
vpoint v[8], s, e;
cpoint cp[8];
double len, x, y, z, angle;
scanf("%lf%lf%lf%lf", &len, &x, &y, &z);
scanf("%lf%lf%lf", &s.x, &s.y, &s.z);
scanf("%lf%lf%lf", &e.x, &e.y, &e.z);
scanf("%lf", &angle);
angle *= pi / 180;
for (int i = 0; i < 8; ++i) {
v[i].x = x + dir[i][0] * len;
v[i].y = y + dir[i][1] * len;
v[i].z = z + dir[i][2] * len;
v[i] = rotate(v[i], s, e, angle);
cp[i] = cpoint(v[i].x, v[i].y);
}
cpoint ch[10];
int m;
graham(cp, 8, ch, m);
printf("%.2lf
", PolygonArea(ch, m));
}
int main() {
#ifndef ONLINE_JUDGE
freopen("D:\\in.txt", "r", stdin);
#endif
int cas;
scanf("%d", &cas);
while (cas--) {
solve();
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Excel을 LaTex 테이블로 변환하는 방법 | Convert Excel to LaTex table이 기사에서는 온라인에서 빠르게 Excel을 LaTex 테이블 마크 업으로 변환하는 방법을 배웁니다. 그리고 다른 스프레드시트 프로그램 데이터를 LaTex 테이블로 변환하는 방법. Excel 데이터를 LaTex로 변...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.