图形学算法小题

一、给定一个二维的多边形,判断它是否为凸多边形

在这里插入图片描述

原理:凸多边形的每个内角都小于180度。

思路:得到所有边的顺时针或者逆时针表示向量,对于每一条边,当前边和下一条边的叉积都大于零。

二、判断点是否在凸多边形内

应用:光线追踪中,射线与三角形所在平面求交后判断交点是否在三角形内部 -> 光线与该三角形是否有交点

方法一 叉积法

思路:针对所有点,计算该点与多边形顶点之间向量的叉积,如果所有叉积同向则说明在内部,如果有反向则说明在外部。

在这里插入图片描述

方法二 同侧法

思路:针对所有边,判断点是否在所有边的同一侧。计算所有边 和 边的起点到所求点的向量 的叉积,如果所有叉积同向则说明在内部,如果有反向则说明在外部。

在这里插入图片描述

三、已知入射向量和法向量,求反射向量

假设L为入射向量,N为法向量,R为所求的反射向量。且为了简化计算,均为单位向量

在这里插入图片描述

令L在N上的投影的反向量为S


R = L + 2 S R=L+2S R=L+2S

S = − ( L ⋅ N ) ⋅ N S=-(L·N)·N S=(LN)N

可得
R = L − 2 ( L ⋅ N ) ⋅ N R=L-2(L·N)·N R=L2(LN)N

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
算法sicily例题 1000. sicily 1155. Can I Post the lette Time Limit: 1sec Memory Limit:32MB Description I am a traveler. I want to post a letter to Merlin. But because there are so many roads I can walk through, and maybe I can’t go to Merlin’s house following these roads, I must judge whether I can post the letter to Merlin before starting my travel. Suppose the cities are numbered from 0 to N-1, I am at city 0, and Merlin is at city N-1. And there are M roads I can walk through, each of which connects two cities. Please note that each road is direct, i.e. a road from A to B does not indicate a road from B to A. Please help me to find out whether I could go to Merlin’s house or not. Input There are multiple input cases. For one case, first are two lines of two integers N and M, (N<=200, M<=N*N/2), that means the number of citys and the number of roads. And Merlin stands at city N-1. After that, there are M lines. Each line contains two integers i and j, what means that there is a road from city i to city j. The input is terminated by N=0. Output For each test case, if I can post the letter print “I can post the letter” in one line, otherwise print “I can't post the letter”. Sample Input 3 2 0 1 1 2 3 1 0 1 0 Sample Output I can post the letter I can't post the letter Source Code #include <iostream> #include <vector> using namespace std; int n,m; vector<int> vout[200]; bool visited[200]; bool flood(int u) { visited[u]=1; if (u==n-1) return 1; for (int x=0; x<vout[u].size(); x++) { int &v=vout[u][x]; if (!visited[v] && flood(v)) return 1; } return 0; }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值