在下面的图片中:
alt text http://rookery9.aviary.com.s3.amazonaws.com/4478500/4478952_3e06_625x625.jpg
我想要连接上面的框和下面的框,我们将上面框的底部边缘称为A,下面框的顶部边缘称为B。
现在,我有两个包含线段A和B中点的数组,例如:
A = [ {Ax1, Ay1},{Ax2, Ay2},.... ] 和 B = [ {Bx1, By1},{Bx2, By2},.... ]
在实际世界中,它可能像这样:A = [ {100, 100},{120, 100},{140, 100},{160, 100}] 和 B=[ {120, 200},{140, 200},{160, 200},{180, 200},{200, 200}]
请查看上面图片中的黑点。
如何获得如图所示的连接点?连接点必须尽可能靠近线的中心。
这是我想要的结果,但下面的函数会从两条线的左侧开始绘制两个匹配点之间的线。有什么建议吗?
-- 更新
我想要的是类似于这个http://raphaeljs.com/graffle.html的东西,但是连接应该像下面展示的那样用直线连接。 alt text http://rookery9.aviary.com.s3.amazonaws.com/4480500/4480527_1e77_625x625.jpg
现在,我有两个包含线段A和B中点的数组,例如:
A = [ {Ax1, Ay1},{Ax2, Ay2},.... ] 和 B = [ {Bx1, By1},{Bx2, By2},.... ]
在实际世界中,它可能像这样:A = [ {100, 100},{120, 100},{140, 100},{160, 100}] 和 B=[ {120, 200},{140, 200},{160, 200},{180, 200},{200, 200}]
请查看上面图片中的黑点。
如何获得如图所示的连接点?连接点必须尽可能靠近线的中心。
这是我想要的结果,但下面的函数会从两条线的左侧开始绘制两个匹配点之间的线。有什么建议吗?
drawConnection : function(componentOut, componentIn, connectionKey) {
var outDim = $(componentOut).data('dim');
var inDim = $(componentIn).data('dim');
var outPorts = $(componentOut).data('ports');
var inPorts = $(componentIn).data('ports');
var abovePorts = {};
var belowPorts = {};
var i = 0;
if(outDim.bottomLeft.y < inDim.topLeft.y){
// Now proceed only if they can be connect with a single line
if(outDim.bottomLeft.x < inDim.topRight.x && outDim.bottomRight.x>inDim.topLeft.x) {
// Now get a proper connecting point
abovePorts = outPorts.bottom;
belowPorts = inPorts.top;
for(i=0; i<abovePorts.length; i++) {
for(j=0; j<belowPorts.length; j++) {
if(!abovePorts[i].inUse && !belowPorts[j].inUse && (abovePorts[i].x == belowPorts[j].x)){
console.debug("Drawing vertical lines between points ("+abovePorts[i].x+","+abovePorts[i].y+") and ("+abovePorts[i].x+","+belowPorts[j].y+")");
return true;
}
}
}
}
}
return false;
},
-- 更新
我想要的是类似于这个http://raphaeljs.com/graffle.html的东西,但是连接应该像下面展示的那样用直线连接。 alt text http://rookery9.aviary.com.s3.amazonaws.com/4480500/4480527_1e77_625x625.jpg