Processing平台之PVector求角度
2024-09-05 00:10:08
问题:在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( ) 的角度与此计算值是相反的 左转为负
最新文章
- 【精粹系列】Mysql精粹
- web.Config配置数据库的连接
- ieee80211w
- Atitit &#160;循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate).
- Android:View随手指移动
- jquery-lazyload延迟加载图片 及 加载顺序 bug 修复
- JavaSE复习_3 继承
- 在同一台机器上让Microsoft SQL Server 2000/ SQL2005/ SQL2008共存
- canvas 渐变
- 翻译-你必须知道的28个HTML5特征、窍门和技术
- mongodb 安装到创建用户,认证auth,httpinterface
- 用js来实现那些数据结构(栈01)
- 无service.bat的tomcat服务怎么设置自启动
- Mock7 moco框架重定向
- 关于Excel报错
- jenkins git ftp 发布.net 项目
- 锦囊9-if语句
- centos查看自启动服务
- DMA与cache一致性的问题
- 【HTTP缓存】浏览器缓存理论知识
热门文章
- 【Scrapy(三)】Scrapy 中的 logging 模块
- Windows驱动派遣函数的学习
- Android平台的so注入--LibInject
- VPS、云主机 and 服务器集群、云计算 的区别
- 洛谷P1553 数字反转(升级版)
- 逆向 ctype.h 函数库 isalnum、iscntrl、islower、isxdigit、tolower 函数
- Win64 驱动内核编程-32.枚举与删除注册表回调
- Java发送邮件报错:com.sun.mail.util.LineOutputStream.<;init>;(Ljava/io/OutputStream;Z)V
- TortoiseGit:拉代码密码错误remote: Coding 提示: Authentication failed! 认证失败,请确认您输入了正确的账号密码
- HDU - 1789 Doing Homework again(贪心) ~~~学了一波sort对结构体排序