问题:在processing 平台,通过给定三个PVector向量,如何求他们之间的夹角,同时确定是在左侧还是右侧?

如图所示,在processing 平台中,PVector表示点的坐标是以原点为起点的向量:

假定有四个点向量PVector,即为:edgeOne, edgeTwo, inter, pre
三个方向向量(通过向量之间的坐标加减得到), 即为:aimOne, aimTwo, intpre
则:
向量aimOne 和 intpre 之间的夹角和方向是多少?
向量aimTwo 和 intpre 之间的夹角和方向是多少?

方法:直接调用以下函数即可:

  float getAngle(PVector pre1, PVector middle, PVector next) {
// calc PVector
PVector pre = new PVector(pre1.x, pre1.y);
PVector inter = new PVector(middle.x, middle.y); PVector edgeOne = new PVector(next.x, next.y);
PVector aimOne = edgeOne.sub(inter);
PVector intpre = inter.sub(pre); // change inter float deviationAngle = atan2(intpre.y, intpre.x) - atan2(aimOne.y, aimOne.x);
if ( deviationAngle > PI ) {
deviationAngle -= TWO_PI;
} else if (deviationAngle < -PI) {
deviationAngle += TWO_PI;
} return degrees(deviationAngle);
}

getAngle(pre, inter, edgeOne);
getAngle(pre, inter, edgeTwo);

说明:

此函数将角度值转换为[-180, 180],  右侧为负,左侧为正,同向为0

PS:但是,PVector.rotate( ) 的角度与此计算值是相反的 左转为负

最新文章

  1. 【精粹系列】Mysql精粹
  2. web.Config配置数据库的连接
  3. ieee80211w
  4. Atitit &#160;循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate).
  5. Android:View随手指移动
  6. jquery-lazyload延迟加载图片 及 加载顺序 bug 修复
  7. JavaSE复习_3 继承
  8. 在同一台机器上让Microsoft SQL Server 2000/ SQL2005/ SQL2008共存
  9. canvas 渐变
  10. 翻译-你必须知道的28个HTML5特征、窍门和技术
  11. mongodb 安装到创建用户,认证auth,httpinterface
  12. 用js来实现那些数据结构(栈01)
  13. 无service.bat的tomcat服务怎么设置自启动
  14. Mock7 moco框架重定向
  15. 关于Excel报错
  16. jenkins git ftp 发布.net 项目
  17. 锦囊9-if语句
  18. centos查看自启动服务
  19. DMA与cache一致性的问题
  20. 【HTTP缓存】浏览器缓存理论知识

热门文章

  1. 【Scrapy(三)】Scrapy 中的 logging 模块
  2. Windows驱动派遣函数的学习
  3. Android平台的so注入--LibInject
  4. VPS、云主机 and 服务器集群、云计算 的区别
  5. 洛谷P1553 数字反转(升级版)
  6. 逆向 ctype.h 函数库 isalnum、iscntrl、islower、isxdigit、tolower 函数
  7. Win64 驱动内核编程-32.枚举与删除注册表回调
  8. Java发送邮件报错:com.sun.mail.util.LineOutputStream.&lt;init&gt;(Ljava/io/OutputStream;Z)V
  9. TortoiseGit:拉代码密码错误remote: Coding 提示: Authentication failed! 认证失败,请确认您输入了正确的账号密码
  10. HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序