Archived

This topic is now archived and is closed to further replies.

splitting polygons

This topic is 5276 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi.. using following function to split a polygon, however, it appears to occasionally create erroneous output when splitting many-sided polygons (all of which are convex) //split a polygon by a plane void split(PLANE3D &partition, POLYGON3D &front, POLYGON3D &back) { //number of points in two resulting polygons int out_c = 0, in_c = 0; //two temporary points for testing VERTEX3D ptA, ptB; //points in resulting polygons VERTEX3D outpts[64], inpts[64]; //two distances from the plane for ptA & ptB double sideA, sideB; //ensure points in polygon are sorted before splitting sort(); //store ptA ptA = points[count - 1]; //calculate distance from plane of ptA sideA = partition.distance(ptA); //loop through all the points for (short i = -1; ++i < count { //store ptB distance from partition ptB = points; sideB = partition.distance(ptB); //test where the two ponits lie if (sideB > EPSILON) { //test sideA if (sideA < -EPSILON) { //compute intersection point of line //from ptA to ptB with the partition. VECTOR3D v = ptB - ptA; double sect = - partition.distance(ptA) / (partition.normal().dotProduct(v)); VERTEX3D add(ptA.x + (v.x * sect), ptA.y + (v.y * sect), ptA.z + (v.z * sect)); //add the point outpts[out_c++] = inpts[in_c++] = add; } outpts[out_c++] = ptB; } //test sideB else if (sideB < -EPSILON) { //test sideA if (sideA > EPSILON) { //compute intersection point of line //from ptA to ptB with the partition. VECTOR3D v = ptB - ptA; double sect = - partition.distance(ptA) / (partition.normal().dotProduct(v)); VERTEX3D add(ptA.x + (v.x * sect), ptA.y + (v.y * sect), ptA.z + (v.z * sect)); //add the point outpts[out_c++] = inpts[in_c++] = add; } inpts[in_c++] = ptB; } //line is on plane else { outpts[out_c++] = inpts[in_c++] = ptB; } ptA = ptB; sideA = sideB; } //create new polygons front = POLYGON3D(outpts, out_c); front.plane = plane; sort(); back = POLYGON3D(inpts, in_c); back.plane = plane; sort(); } can anyone spot any glaring mistakes? cheers in advance

Share this post


Link to post
Share on other sites
You might want to take out the smiley face from your code. My compiler always barfs at me when I put smileys in.

error C2142: emoticon error : Programmer too happy

Share this post


Link to post
Share on other sites