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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
U
Unit 42
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
InfoQ
博客园 - 司徒正美

博客园 - 镜涛

Spark环境搭建遇到的问题 This installation has not been configured properly for Software Updates The Activator X for bundle Y is invalid, caused by ClassNotFoundException: X SAP全球技术大会参会随笔 工作流系统概述 需要掌握的flex知识点 ORA-01460: 转换请求无法实现或不合理 去除对象中的类型集合 【转载】Tomcat内存溢出的原因及调试 做产品开发的感想 基于SAML的单点登录.NET代理端实现方案 Cursor identified in Fetch statement is not open Java下载中文乱码问题解决方法 - 镜涛 - 博客园 Could not find the main class. Program will exit. - 镜涛 Unrecognized attribute 'targetFramework'.错误解决 [译]Razor内幕之模板 - 镜涛 - 博客园 [译]Razor内幕之表达式 - 镜涛 - 博客园 [译]Razor内幕之解析 [译]Razor内幕之介绍
获取矩形中心点与矩形外某点连线和矩形交点的算法
镜涛 · 2010-12-06 · via 博客园 - 镜涛

  图形化广泛应用于各种系统中,包括ESB的适配,业务流程的建模,工作流程的定制,数据交换系统的配置等等,这其中不可避免的需要用到各种图形符号来直观、清晰的表达抽象的内容。一般来说,我们会通过标准的图形来表述特定的含义,达到交流的目的,而图形间信息导向一般都是通过线来完成的,一个好的画线算法,不仅能够让业务或者配置图更加美观,也更能清晰的向受众表述业务或者配置内容。

  本文实现了一个获取矩形中心点与矩形外某点连线与矩形交点的算法。实现语言为ActionScript。

1 /**
2 * 获得一个矩形中心点到矩形外某点之间的连线与矩形的交点
3 * 算法思路:
4 * 以矩形外的某点为坐标原点,将图形分为四个象限,每个象限分两种情况,坐标轴上单独处理
5 * 1.坐标轴的情况:
6 * 1.负x轴的情况
7 * 2.正x轴的情况
8 * 3.正y轴的情况
9 * 4.负y轴的情况
10 * 2.象限情况:
11 * 2.1.第一象限:连线与矩形左边相交的情况;与矩形下边相交的情况
12 * 2.2.第二象限:连线与矩形右边相交的情况;与矩形下边相交的情况
13 * 2.3.第三象限:连线与矩形右边相交的情况;与矩形上边相交的情况
14 * 2.4.第四象限:连线与矩形左边相交的情况;与矩形上边相交的情况
15 *
16 * */
17 private function getIntersectPoint(fromNode:Rectangle,endPoint:Point):Point
18 {
19 //开始矩形的x坐标
20   var x1:Number=fromNode.x;
21 //开始矩形的y坐标
22   var y1:Number=fromNode.y;
23 //结束点的x坐标
24 var x2:Number=endPoint.x;
25 //结束点的y坐标
26 var y2:Number=endPoint.y;
27
28 //开始矩形的中心点x坐标
29 var fromCenterX:Number=x1+fromNode.width/2;
30 //开始矩形的中心点的y坐标
31 var fromCenterY:Number=y1+fromNode.height/2;
32 //矩形和点之间的x坐标相对距离
33 var dx:Number=Math.abs(x1-x2);
34 //矩形和点之间的y坐标相对距离
35 var dy:Number=Math.abs(y1-y2);
36 //相对距离的正切值
37 var tanDYX:Number=dy/dx;
38 //开始矩形的正切值
39 var fromDYX:Number=fromNode.height/fromNode.width;
40
41 var returnPoint:Point=null;
42 //负x轴
43 if(y1==y2&&x1<x2)
44 {
45 returnPoint= new Point(x1+fromNode.width,fromCenterY);
46 }
47 //正x轴
48 else if(y1==y2&&x1>x2)
49 {
50 returnPoint= new Point(x1,fromCenterY);
51 }
52 //正y轴
53 else if(x1==x2&&y1<y2)
54 {
55 returnPoint= new Point(fromCenterX,y1+fromNode.height);
56 }
57 //负y轴
58 else if(x1==x2&&y1>y2)
59 {
60 returnPoint= new Point(fromCenterX,y1);
61 }
62 //第一象限
63 if(x1>x2&&y1<y2)
64 {
65 if(fromDYX>=tanDYX)
66 {
67 returnPoint= new Point(x1,fromCenterY+tanDYX*fromNode.width/2);
68 }
69 else
70 {
71 returnPoint= new Point(fromCenterX-dx/dy*fromNode.height/2,y1+fromNode.height);
72 }
73 }
74 //第二象限
75 else if(x1<x2&&y1<y2)
76 {
77 //
78 if(fromDYX>=tanDYX)
79 {
80 returnPoint= new Point(x1+fromNode.width,fromCenterY+tanDYX*fromNode.width/2);
81 }
82 else
83 {
84 returnPoint= new Point(fromCenterX+dx/dy*fromNode.height/2,y1+fromNode.height);
85 }
86
87 }
88 //第三象限
89 else if(x1<x2&&y1>y2)
90 {
91 if(fromDYX>=tanDYX)
92 {
93 returnPoint= new Point(x1+fromNode.width,fromCenterY-tanDYX*fromNode.width/2);
94 }
95 else
96 {
97 returnPoint= new Point(fromCenterX+fromNode.height/2*dx/dy,y1);
98 }
99 }
100 //第四象限
101 else if(x1>x2&&y1>y2)
102 {
103 if(fromDYX>=tanDYX)
104 {
105 returnPoint= new Point(x1,fromCenterY-fromNode.width/2*tanDYX);
106 }
107 else
108 {
109 returnPoint= new Point(fromCenterX-fromNode.height/2*dx/dy,y1);
110 }
111 }
112 return returnPoint;
113 }
114