惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
F
Full Disclosure
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
Hacker News: Ask HN
Hacker News: Ask HN
V
Visual Studio Blog
IT之家
IT之家
N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
月光博客
月光博客
H
Heimdal Security Blog
T
The Blog of Author Tim Ferriss
腾讯CDC
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Troy Hunt's Blog
小众软件
小众软件
Jina AI
Jina AI
博客园 - Franky
Scott Helme
Scott Helme
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
TaoSecurity Blog
TaoSecurity Blog
F
Fortinet All Blogs
Y
Y Combinator Blog
P
Privacy & Cybersecurity Law Blog
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
量子位
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Last Watchdog
The Last Watchdog
博客园 - 三生石上(FineUI控件)
L
LINUX DO - 最新话题

博客园 - 鹅要长大

【c++编程基础】理解lambda表达式 【c++编程基础】字节对齐pack的理解 【c++编程基础】虚函数virtual的理解与使用 【linux基础知识】理解nohup 【linux基础】如何理解python train_dtld.py 2>&1 | tee my_error_log.txt 【工具使用】docker的使用 【基础算法】银行家舍入法 【ubuntu工具】ubuntu好用工具总结 【ubuntu基础工具使用】ubuntu中screen的安装与使用 【linux操作基础】多目录文件复制且同名不覆盖 【linux基础操作】windows系统生成的txt文件在ubuntu打开乱码 【opencv编程基础】fillpoly和polylines函数的理解 【c++编程基础】std::unique的理解 【计算几何算法】道格拉斯普克(Douglas-Peuker)算法 [c++]c++ 工程代码中的debug时条件编译隐去的代码会影响程序运行的性能和耗时吗 【CV基础】语义分割任务计算类别权重 【opencv基础】resize使用的问题 git stash的用法 gflags的使用 opencv 判断某个坐标点是否在多边形内cv::pointPolygonTest 判断多边形的顶点内外角点以及对approxPolyDP函数的理解 用Python从零实现贝叶斯分类器 【CV数据集】智慧城市之CCPD车牌数据集
【编程基础】计算三个顶点之间的夹角
鹅要长大 · 2024-12-09 · via 博客园 - 鹅要长大

前言

code

float calculateAngle(cv::Point pre, cv::Point cur, cv::Point next){
    cv::Point v1 = {pre.x-cur.x, pre.y-cur.y}; // ABC, BA
    cv::Point v2 = {next.x-cur.x, next.y-cur.y}; // ABC, BC
    double dotProduct = v1.x * v2.x + v1.y * v2.y;
    double normProduct = std::sqrt(v1.x * v1.x + v1.y * v1.y) * std::sqrt(v2.x * v2.x + v2.y * v2.y);
    float angleR = std::acos(dotProduct / normProduct);
    // Convert from radians to degrees
    float angleD =  angleR * 180.0 / CV_PI;
    return  angleD;   
}

float calculateAngleB(cv::Point pre, cv::Point cur, cv::Point next) {  
    cv::Point v1 = {cur.x - pre.x, cur.y - pre.y};  
    cv::Point v2 = {next.x - cur.x, next.y - cur.y}; // 修正了向量v2的计算  
    double dotProduct = v1.x * v2.x + v1.y * v2.y;  
    double normProduct = std::sqrt(v1.x * v1.x + v1.y * v1.y) * std::sqrt(v2.x * v2.x + v2.y * v2.y);  
    double angleRadians = std::acos(dotProduct / normProduct); // 使用double类型来保持精度  
    float angleDegrees = static_cast<float>(angleRadians * 180.0 / CV_PI); // 将弧度转换为度数并转换为float类型  
    return (180.0-angleDegrees);  
}

// 计算两点间距离的函数  
double distance(cv::Point p1, cv::Point p2) {  
    return std::sqrt(std::pow(p2.x - p1.x, 2) + std::pow(p2.y - p1.y, 2));  
} 

float calculateAngleC(cv::Point A, cv::Point B, cv::Point C) {  
    // 计算三角形的三边长度  
    double a = distance(B, C); // BC边  
    double b = distance(A, C); // AC边  
    double c = distance(A, B); // AB边  
    // 应用余弦定理计算cosB  
    double cosB = (a * a + c * c - b * b) / (2 * a * c);  
    // 注意:acos函数返回的是弧度值,需要转换为度数  
    // 转换公式为:度数 = 弧度 * 180 / π  
    float angleB_degrees = std::acos(cosB) * 180.0 / CV_PI; // M_PI是math.h中定义的π值  
    // 返回角B的度数  
    return angleB_degrees;  
}  

View Code

参考

1.

各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。

Simple is clean. Complex is clever.
Logic & Aesthetics
Seeking Ground Truth within the pixels.

版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/