uva 11275 3D Triangles (3D-Geometry)
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2250
判断两个空间中的三角形是否有公共点。
代码如下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm> using namespace std; struct Point3 {
double x[];
Point3() {}
Point3(double *_x) { for (int i = ; i < ; i++) x[i] = _x[i];}
} ;
typedef Point3 Vec3; Vec3 operator + (Vec3 a, Vec3 b) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] + b.x[i];
return ret;
}
Vec3 operator - (Vec3 a, Vec3 b) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] - b.x[i];
return ret;
}
Vec3 operator * (Vec3 a, double p) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] * p;
return ret;
}
Vec3 operator / (Vec3 a, double p) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] / p;
return ret;
} const double EPS = 1e-;
inline int sgn(double x) { return (x > EPS) - (x < -EPS);} bool operator < (Point3 a, Point3 b) {
for (int i = ; i < ; i++) {
if (sgn(a.x[i] - b.x[i])) return a.x[i] < b.x[i];
}
return true;
}
bool operator == (Point3 a, Point3 b) {
for (int i = ; i < ; i++) {
if (sgn(a.x[i] - b.x[i])) return false;
}
return true;
} double dotDet(Vec3 a, Vec3 b) {
double ret = 0.0;
for (int i = ; i < ; i++) ret += a.x[i] * b.x[i];
return ret;
}
inline double dotDet(Point3 o, Point3 a, Point3 b) { return dotDet(a - o, b - o);}
inline Vec3 crossDet(Vec3 a, Vec3 b) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[(i + ) % ] * b.x[(i + ) % ] - b.x[(i + ) % ] * a.x[(i + ) % ];
return ret;
}
inline Vec3 crossDet(Point3 o, Point3 a, Point3 b) { return crossDet(a - o, b - o);}
inline double vecLen(Vec3 x) { return sqrt(dotDet(x, x));}
inline double angle(Vec3 a, Vec3 b) { return acos(dotDet(a, b) / vecLen(a) / vecLen(b));}
inline double ptDis(Point3 a, Point3 b) { return vecLen(a - b);}
inline double triArea(Point3 a, Point3 b, Point3 c) { return vecLen(crossDet(a, b, c));}
inline Vec3 vecUnit(Vec3 x) { return x / vecLen(x);} struct Plane {
Point3 p;
Vec3 n;
Plane() {}
Plane(Point3 p, Vec3 n) : p(p), n(n) {}
Plane(Point3 a, Point3 b, Point3 c) { p = a; n = crossDet(b - a, c - a);}
} ;
inline double pt2Plane(Point3 p, Point3 p0, Vec3 n) { return dotDet(p - p0, n) / vecLen(n);}
inline double pt2Plane(Point3 p, Plane P) { return pt2Plane(p, P.p, P.n);}
inline Point3 ptOnPlane(Point3 p, Point3 p0, Vec3 n) { return p + n * pt2Plane(p, p0, n);}
inline Point3 ptOnPlane(Point3 p, Plane P) { return ptOnPlane(p, P.p, P.n);}
inline bool ptInPlane(Point3 p, Point3 p0, Vec3 n) { return sgn(dotDet(p - p0, n)) == ;}
inline bool ptInPlane(Point3 p, Plane P) { return ptInPlane(p, P.p, P.n);} int linePlaneIntersect(Point3 s, Point3 t, Point3 p0, Vec3 n, Point3 &x) {
double res1 = dotDet(n, p0 - s);
double res2 = dotDet(n, t - s);
if (sgn(res2) == ) {
if (ptInPlane(s, p0, n)) return ;
return ;
}
x = s + (t - s) * (res1 / res2);
return ;
} bool ptInTri(Point3 p, Point3 *tri) {
double area = triArea(tri[], tri[], tri[]);
double sum = 0.0;
for (int i = ; i < ; i++) sum += triArea(p, tri[i], tri[(i + ) % ]);
return sgn(sum - area) == ;
} bool triSegIntersect(Point3 *tri, Point3 s, Point3 t) {
Vec3 n = crossDet(tri[], tri[], tri[]);
if (sgn(dotDet(n, t - s)) == ) return false;
else {
double k = dotDet(n, tri[] - s) / dotDet(n, t - s);
if (sgn(k) < || sgn(k - ) > ) return false;
Point3 x = s + (t - s) * k;
return ptInTri(x, tri);
}
} Point3 tri[][]; bool check() {
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
if (triSegIntersect(tri[i], tri[i ^ ][j], tri[i ^ ][(j + ) % ])) return true;
}
}
return false;
} int main() {
// freopen("in", "r", stdin);
int n;
cin >> n;
while (n--) {
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
for (int k = ; k < ; k++) {
cin >> tri[i][j].x[k];
}
}
}
cout << check() << endl;
}
return ;
}
——written by Lyon
uva 11275 3D Triangles (3D-Geometry)的更多相关文章
- Multi-View 3D Reconstruction with Geometry and Shading——Part-2
From PhDTheses Multi-View 3D Reconstruction with Geometry and Shading 我们的主要目标是只利用图像中的信息而没有额外的限制或假设来得 ...
- Multi-View 3D Reconstruction with Geometry and Shading——Part-1
From PhDTheses Multi-View 3D Reconstruction with Geometry and Shading 计算机视觉的主要任务就是利用图像信息能智能理解周围的世界. ...
- 如何用webgl(three.js)搭建一个3D库房,3D密集架,3D档案室,-第二课
闲话少叙,我们接着第一课继续讲(http://www.cnblogs.com/yeyunfei/p/7899613.html),很久没有做技术分享了.很多人问第二课有没有,我也是抽空写一下第二课. 第 ...
- webgl(three.js)实现室内三维定位,3D定位,3D楼宇bim、实时定位三维可视化解决方案——第十四课(定位升级版)
序: 还是要抽出时间看书的,迷上了豆豆的作品,最近在看<天幕红尘>,书中主人公的人生价值观以及修为都是让我惊为叹止.很想成为那样的人,但是再看看自己每天干的事,与时间的支配情况,真是十分的 ...
- 教你调节Boom 3D的3D音效强度,让音乐更带感
Boom 3D的专业3D环绕技术,让用户能全身心地沉浸在立体音效中.无论是聆听音乐,还是观赏电影,立体音效都能为人们带来更加真实的听觉感触. 那么,Boom 3D的3D环绕功能到底能给用户带来怎样的体 ...
- 如何用webgl(three.js)搭建一个3D库房,3D密集架,3D档案室(升级版)
很长一段时间没有写3D库房,3D密集架相关的效果文章了,刚好最近有相关项目落地,索性总结一下 与之前我写的3D库房密集架文章<如何用webgl(three.js)搭建一个3D库房,3D密集架,3 ...
- 如何用webgl(three.js)搭建一个3D库房,3D仓库,3D码头,3D集装箱可视化孪生系统——第十五课
序 又是快两个月没写随笔了,长时间不总结项目,不锻炼文笔,一开篇,多少都会有些生疏,不知道如何开篇,如何写下去.有点江郎才尽,黔驴技穷的感觉. 写随笔,通常三步走,第一步,搭建框架,先把你要写的内容框 ...
- 如何用webgl(three.js)搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课
序 又是快两个月没写随笔了,长时间不总结项目,不锻炼文笔,一开篇,多少都会有些生疏,不知道如何开篇,如何写下去.有点江郎才尽,黔驴技穷的感觉. 写随笔,通常三步走,第一步,搭建框架,先把你要写的内容框 ...
- webgl(three.js)3D光伏,3D太阳能能源,3D智慧光伏、光伏发电、清洁能源三维可视化解决方案——第十六课
序: 能源是文明和发展的重要保障,人类命运不可避开的话题,无论是战争还是发展,都有它存在的身影.从石器时代到现代文明,人类的能源应用在进步,也在面临能源枯竭的危机与恐惧,而开发与应用可再生能源才是解决 ...
- 如何使用webgl(three.js)实现3D储能,3D储能站,3D智慧储能、储能柜的三维可视化解决方案——第十七课
前言 上节课我们讲了<3D光伏发电>,与之配套的就是能量存储 这节课我们主要讲讲储能,储能站,在分布式能源系统中起到调节用对电的尖峰平谷进行削峰填谷的作用.特别是小型储能站,更加灵活,因地 ...
随机推荐
- Mybatis错误:Result Maps collection already contains value for ***
[转载]原文链接:https://blog.csdn.net/maoyuanming0806/article/details/77870345 使用mybatis时,服务器启动时出错 严重: Exce ...
- 【python之路20】函数作为参数
1.函数可以作为参数 1)函数名相当于变量指向函数 2)函数名后面加括号表示调用函数 #!usr/bin/env python # -*- coding:utf-8 -*- def f1(args): ...
- php thrift TServerSocket实现端口复用
<?php namespace Message\Controller; use Think\Controller; use Thrift\Exception\TException; use Th ...
- Beetl 3中文文档 转载 http://ibeetl.com/guide/
Beetl作者:李家智(闲大赋) <xiandafu@126.com> 1. 什么是Beetl 广告:闲大赋知识星球,付费会员 Beetl( 发音同Beetle ) 目前版本是3.0.7, ...
- 洛谷 P1119 灾后重建 最短路+Floyd算法
目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例 输出样例 说明 思路 AC代码 总结 题面 题目链接 P1119 灾后重建 题目描述 B地区在地震过后,所有村 ...
- vuxdemo1
//main.js import Vue from 'vue' import router from './router' import store from './store' import axi ...
- MUI - sortable在mui.js前端框架不兼容的解决方案
关于sortable看这 兼容的解决方案看这 http://www.cnblogs.com/phillyx/ 示例代码已更到github
- springboot 启动配置原理【转】【补】
创建应用 几个重要的事件回调机制 , 配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunL ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数 学习目标: 理解矩阵和与它相关的运算: 理解矩阵的乘 ...
- 直击 KubeCon 2019 现场,阿里云 Hands-on Workshop 亮点回顾
2019 年 6 月 24 日,KubeCon + CloudNativeCon 第二次在中国举办.此次大会阿里共有 26 个技术演讲入选,并有两场沙龙活动,阿里云专家也与技术极客们也再次相聚.Kub ...