Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in the function for intersection area between a triangle and circle #1

Open
TakeuchiHiroshi opened this issue Nov 20, 2019 · 0 comments

Comments

@TakeuchiHiroshi
Copy link

-- test code ---

TCircle2<double> C(TPt2<double>::Origin, 5);
TTriangle2<double> tri(TPt2<double>(3,3), TVec2<double>(1,0), TVec2<double>(0,1));
double area = IntersectionArea(tri, C);

--Result(with TINTERSECTION2_DEBUG)---

Intersection triangle {3, 3),{4, 3),{3, 4) with circle {0, 0),5
 nxp[i] = 1 nxp[i] = 2 nxp[i] = 1
 inside = 7
 nv = 7 
 added triangle area, now area = 0
 added triangle area, now area = 0
 added triangle area, now area = 0.5
 s = 1.41421
 added triangle area, now area = 0.547426
 added triangle area, now area = 0.547426
*** stack smashing detected *** terminated

--- reason ----
The highest index for vtype and vp arrays is 5, but trying to access vtype[6] and vp[6] in the following loop (around line 258 of TIntersection2.hpp):

int vtype[6]; // 1 = triangle vertex, 0 = intersection point
pt_t vp[6];
int nv = 0; // number of actual vertices	
for(int i = 0; i < 3; ++i){
	if(inside & (1 << i)){
		vp[nv] = seg[i][0];
		vtype[nv++] = 1;
	}
	for(int j = 0; j < nxp[i]; ++j){
		vp[nv] = xp[2*i+j];
		vtype[nv++] = 0;
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant