Esempio n. 1
0
// CCW means that in this example we must swap p1 and p2
void Layer::create_segments() {
  
  int skipped = 0, no_intersect=0;
  
  for(linkedlistnode *it = candidates->first; it != NULL; it = it->next ) {
    stl_face *f = (stl_face*) it->payload;
    line *l = intersection_line(f, this->height);
    if (l == 0) {
      no_intersect++;
      continue;
    }

    // the vector from p1 to p2
    const point p1p2 = {l->p2.x - l->p1.x, l->p2.y - l->p1.y};

    // should to short segments be skipped?, yes
    if (std::abs(p1p2.x * p1p2.x + p1p2.y * p1p2.y) < EPSILON * EPSILON) {
      skipped++;
      continue;
    }


    assert(std::abs(p1p2.x * p1p2.x + p1p2.y * p1p2.y) > EPSILON*EPSILON);
    // project onto zx plane, and well call z for y 
    const point normal = {f->normal.x, f->normal.z}; 
    assert(std::abs(normal.x * normal.x + normal.y * normal.y) > EPSILON*EPSILON);

    // we can calculate this as z = 0;
    float cross = p1p2.x*normal.y - p1p2.y * normal.x; 
    // change the order so we are sure that p1 is the first point in a CCW polygon
    if (cross < 0) {
      /* swap p1 and p2 */
      point tmp = l->p1;
      l->p1 = l->p2;
      l->p2 = tmp;
    }
    segments->push_back(l);
  }

  printf("skipping %d short segments and %d none intersecting \n", skipped, no_intersect);
}
Esempio n. 2
0
//static 
// returns 'true' if planes intersect, and stores the result 
// the second and third arguments are treated as planes
// where mPoint is on the plane and mDirection is the normal
// result.mPoint will be the intersection line's closest approach 
// to first_plane.mPoint
bool LLLine::getIntersectionBetweenTwoPlanes( LLLine& result, const LLLine& first_plane, const LLLine& second_plane )
{
	// TODO -- if we ever get some generic matrix solving code in our libs
	// then we should just use that, since this problem is really just
	// linear algebra.

	F32 dot = fabs(first_plane.mDirection * second_plane.mDirection);
	if (dot > ALMOST_PARALLEL)
	{
		// the planes are nearly parallel
		return false;
	}

	LLVector3 direction = first_plane.mDirection % second_plane.mDirection;
	direction.normalize();

	LLVector3 first_intersection;
	{
		LLLine intersection_line(first_plane);
		intersection_line.mDirection = direction % first_plane.mDirection;
		intersection_line.mDirection.normalize();
		intersection_line.intersectsPlane(first_intersection, second_plane);
	}

	/*
	LLVector3 second_intersection;
	{
		LLLine intersection_line(second_plane);
		intersection_line.mDirection = direction % second_plane.mDirection;
		intersection_line.mDirection.normalize();
		intersection_line.intersectsPlane(second_intersection, first_plane);
	}
	*/

	result.mPoint = first_intersection;
	result.mDirection = direction;

	return true;
}