计算几何-Line-Left-Intersect
This article is made by Jason-Cow.
Welcome to reprint.
But please post the article's address.
好好领悟一下vector吧!加一行Left还可以判断是否在直线上...
struct L{ D O;V v;db a; L(){} L(D O,V v):O(O),v(v){a=atan2(O.y,O.x);}//atan2(y,x)=atan(y/x) but the x is OK to be zero bl op<(const L&x)const{return a<x.a;} }; bl Left(D A,L l){return Cross(l.v,A-l.O)>0;}
int main(){ V A(1,1),B(2,2); L l(A,B-A); printf("l( O(%lf,%lf) V(%lf,%lf) a(%lf))\n",l.O.x,l.O.y,l.v.x,l.v.y,l.a); printf("( 1, 3) is on the %s\n",Left(V( 1, 3),l)?"Left":"right"); printf("( 3, 1) is on the %s\n",Left(V( 3, 1),l)?"Left":"right"); printf("(-1, 3) is on the %s\n",Left(V(-1, 3),l)?"Left":"right"); printf("( 0,-2) is on the %s\n",Left(V( 0,-2),l)?"Left":"right"); printf("( 0, 0) is on the %s\n",Left(V( 0, 0),l)?"Left":"right"); return 0; }
l( O(1.000000,1.000000) V(1.000000,1.000000) a(0.785398)) //a=pi/4 ( 1, 3) is on the Left ( 3, 1) is on the right (-1, 3) is on the Left ( 0,-2) is on the right ( 0, 0) is on the right
Intersect(L a,L b)
Return The Dot Of Two Line
D Intersect(L a,L b){ V u=a.O-b.O; return a.O+a.v*(Cross(b.v,u)/Cross(a.v,b.v)); }
int main()
int main(){ L a(D(0,1),D(0,1)-D(-1,0)); L b(D(1,0),D(1,0)-D(0,1)); D A=Intersect(a,b); cout<<"("<<A.x<<","<<A.y<<")"<<endl; return 0; }
(0,1)
~~Jason_liu O(∩_∩)O
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· .NET 进程 stackoverflow异常后,还可以接收 TCP 连接请求吗?
· 本地部署 DeepSeek:小白也能轻松搞定!
· 基于DeepSeek R1 满血版大模型的个人知识库,回答都源自对你专属文件的深度学习。
· 在缓慢中沉淀,在挑战中重生!2024个人总结!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 大人,时代变了! 赶快把自有业务的本地AI“模型”训练起来!