java两园交点,计算两条边的交点

当我计算交叉点时,我在单调边缘上使用扫描线(我有一个排序函数,它对构造函数内的边进行排序,我测试它们,我很好地排序),即使我得到了一些点作为顶点的交点一些边缘,即使我有很多测试来消除这种情况 .

这是第四种方法的代码(到目前为止,它给了我最好的结果,但不是所有的交叉点,但至少与其他交叉点相比有一些好的交叉点):

//4 method

double* QSweep::findIntersection(edge_t edge1,edge_t edge2) {

point_t p1=myPoints_[edge1[0]];

point_t p2=myPoints_[edge1[1]];

point_t p3=myPoints_[edge2[0]];

point_t p4=myPoints_[edge2[1]];

double xD1,yD1,xD2,yD2,xD3,yD3,xP,yP,h,denom;

double* pt=new double[3];

// calculate differences

xD1=p2[0]-p1[0];

xD2=p4[0]-p3[0];

yD1=p2[1]-p1[1];

yD2=p4[1]-p3[1];

xD3=p1[0]-p3[0];

yD3=p1[1]-p3[1];

xP=-yD1;

yP=xD1;

denom=xD2*(-yD1)+yD2*xD1;

if (denom==0) {

return NULL;

}

else{

h=(xD3*(-yD1)+yD3*xD1)/denom;

}

std::cout<

if ((h>0)&&(h<1)){

pt[0]=p3[0]+xD2*h;

pt[1]=p3[1]+yD2*h;

pt[2]=0.00;

}

else{

return NULL;

}

// return the valid intersection

return pt;

}

void QSweep:: intersection(){

nbIntersections=0;

double* vector;

for (int i=2;i

vector=findIntersection(myEdges_[i-1],myEdges_[i]);

if (vector!=NULL){

nbIntersections++;

myIntersections.push_back(vector);

swap(myEdges_[i-1], myEdges_[i]);

}

}

}

交集函数总是相同的,所以我只找到 findIntersection 函数 .

对于1和2方法,我使用以下版本的 findIntersection 函数:

double* QSweep::computeIntersection(double m1, double b1, double m2, double b2){

double* v=new double[3];

v[0]= (b2-b1)/(m1-m2);

v[1]= (m1*b2-m2*b1)/(m1-m2);

v[2]=0.00;

return v;

}

double* QSweep::findIntersection(edge_t edge1, edge_t edge2){

//equation for the support line of the first edge

double a=myPoints_[edge1[0]][0];

double b=myPoints_[edge1[0]][1];

double c=myPoints_[edge1[1]][0];

double d=myPoints_[edge1[1]][1];

double m1=getSlope(a,b,c,d);

double b1=getYIntercept(a,b,c,d);

double x=myPoints_[edge2[0]][0];

double y=myPoints_[edge2[0]][1];

double s=myPoints_[edge2[1]][0];

double t=myPoints_[edge2[1]][1];

double m2=getSlope(x,y,s,t);

double b2=getYIntercept(x,y,s,t);

double* vector;

double line2InLine1=evalEqnLineD(myPoints_[edge2[0]],edge1);

double line2InLine1New=evalEqnLineD(myPoints_[edge2[1]],edge1);

double line1InLine2=evalEqnLineD(myPoints_[edge1[0]],edge2);

double line1InLine2New=evalEqnLineD(myPoints_[edge1[1]],edge2);

if (m1==m2){

return NULL;

}

else{

if ((line1InLine2*line1InLine2New)<0 && (line2InLine1*line2InLine1New)<0){

vector=computeIntersection(m1,b1,m2,b2);

if ((vector[0]>a && vector[0]x && vector[0]

return vector;

}

else{

return NULL;

}

}

else{

return NULL;

}

}

return vector;

}

我将从头开始再看看我想要的交叉点有什么共同之处 . 即使对某些测试很难,我甚至没有得到好的交叉点,但是图中的其他点,所以我真的很困惑 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值