コード例 #1
0
ファイル: main.cpp プロジェクト: BengtHolm/STLexer
void AccumulateArea()
{
	vector<double> area_vector;

	transform( Rect_List.begin(), Rect_List.end(),
				back_inserter( area_vector ), ComputeArea() );
	transform( Tria_List.begin(), Tria_List.end(),
				back_inserter( area_vector ), ComputeArea() );
	transform( Circ_List.begin(), Circ_List.end(),
				back_inserter( area_vector ), ComputeArea() );
	cout << "Accumulate area : " << accumulate(area_vector.begin(), area_vector.end(), 0.0 ) << endl;
}
コード例 #2
0
ファイル: geometry.cpp プロジェクト: Adrian-Revk/radar
/// Same as InitUnit, except the resulting triangle is kept in world space. 
/// triNormal is the normal of the plane collinear with the triangle
void Triangle::InitWS( const vec3f &triNormal, const vec3f &p0, const vec3f &p1, const vec3f &p2, const vec3f &intPos )
{
	unitNormal = triNormal;

	q0 = p0 - intPos;
	q1 = p1 - intPos;
	q2 = p2 - intPos;

	ComputeArea();

	const vec3f bary = ( q0 + q1 + q2 ) * 0.3333333333333f;
	const f32 rayLenSqr = Dot( bary, bary );
	const f32 rayLen = std::sqrt( rayLenSqr );
	solidAngle = -Dot( bary, unitNormal ) * ( area / ( rayLenSqr * rayLen ) );
}
コード例 #3
0
ファイル: geometry.cpp プロジェクト: aksris/PathTracer
float Geometry::RayPDF(const Intersection &isx, const Ray &ray)
{
    //TODO
    //The isx passed in was tested ONLY against us (no other scene objects), so we test if NULL
    //rather than if != this.
    if(isx.object_hit == NULL)
    {
        return 0;
    }
    //Add more here
    //distance between light origin and object surface
    float theta = glm::abs(glm::dot(isx.normal, -ray.direction));
    ComputeArea();
    return pow(glm::length(isx.point-ray.origin), 2.0f) / (theta * area);
}
コード例 #4
0
ファイル: al_geometry.cpp プロジェクト: rafaelclp/icpc-trd
int main() {
	// expected (-5,2)/(5,-2)/(-5,2)/(5,2)/(5,2) (7.5,3) (2.5,1)
	cerr << RotateCCW90(PT(2,5)) << endl;
	cerr << RotateCW90(PT(2,5)) << endl;
	cerr << RotateCCW(PT(2,5),M_PI/2) << endl;
	cerr << ProjectPointLine(PT(-5,-2), PT(10,4), PT(3,7)) << endl;
	cerr << ProjectPointSegment(PT(-5,-2), PT(10,4), PT(3,7)) << " "
		 << ProjectPointSegment(PT(7.5,3), PT(10,4), PT(3,7)) << " "
		 << ProjectPointSegment(PT(-5,-2), PT(2.5,1), PT(3,7)) << endl;

	// expected 6.78903/1 0 1/0 0 1/1 1 1 0/(1,2)/(1,1)
	cerr << DistancePointPlane(4,-4,3,2,-2,5,-8) << endl;
	cerr << LinesParallel(PT(1,1), PT(3,5), PT(2,1), PT(4,5)) << " "
		 << LinesParallel(PT(1,1), PT(3,5), PT(2,0), PT(4,5)) << " "
		 << LinesParallel(PT(1,1), PT(3,5), PT(5,9), PT(7,13)) << endl;
	cerr << LinesCollinear(PT(1,1), PT(3,5), PT(2,1), PT(4,5)) << " "
		 << LinesCollinear(PT(1,1), PT(3,5), PT(2,0), PT(4,5)) << " "
		 << LinesCollinear(PT(1,1), PT(3,5), PT(5,9), PT(7,13)) << endl;
	cerr << SegmentsIntersect(PT(0,0), PT(2,4), PT(3,1), PT(-1,3)) << " "
		 << SegmentsIntersect(PT(0,0), PT(2,4), PT(4,3), PT(0,5)) << " "
		 << SegmentsIntersect(PT(0,0), PT(2,4), PT(2,-1), PT(-2,1)) << " "
		 << SegmentsIntersect(PT(0,0), PT(2,4), PT(5,5), PT(1,7)) << endl;
	cerr << ComputeLineIntersection(PT(0,0),PT(2,4),PT(3,1),PT(-1,3)) << endl;
	cerr << ComputeCircleCenter(PT(-3,4), PT(6,1), PT(4,5)) << endl;
  
	vector<PT> v; v.push_back(PT(0,0)); v.push_back(PT(5,0));
	v.push_back(PT(5,5)); v.push_back(PT(0,5));
  
	// expected: 1 1 1 0 0
	cerr << PointInPolygon(v, PT(2,2)) << " "
		 << PointInPolygon(v, PT(2,0)) << " "
		 << PointInPolygon(v, PT(0,2)) << " "
		 << PointInPolygon(v, PT(5,2)) << " "
		 << PointInPolygon(v, PT(2,5)) << endl;
  
	// expected: 0 1 1 1 1
	cerr << PointOnPolygon(v, PT(2,2)) << " "
		 << PointOnPolygon(v, PT(2,0)) << " "
		 << PointOnPolygon(v, PT(0,2)) << " "
		 << PointOnPolygon(v, PT(5,2)) << " "
		 << PointOnPolygon(v, PT(2,5)) << endl;
  
	// expected: (1,6)/(5,4) (4,5)//(4,5) (5,4)//(4,5) (5,4)
	vector<PT> u = CircleLineIntersection(PT(0,6), PT(2,6), PT(1,1), 5);
	for (int i = 0; i < u.size(); i++) cerr << u[i] << " "; cerr << endl;
	u = CircleLineIntersection(PT(0,9), PT(9,0), PT(1,1), 5);
	for (int i = 0; i < u.size(); i++) cerr << u[i] << " "; cerr << endl;
	u = CircleCircleIntersection(PT(1,1), PT(10,10), 5, 5);
	for (int i = 0; i < u.size(); i++) cerr << u[i] << " "; cerr << endl;
	u = CircleCircleIntersection(PT(1,1), PT(8,8), 5, 5);
	for (int i = 0; i < u.size(); i++) cerr << u[i] << " "; cerr << endl;
	u = CircleCircleIntersection(PT(1,1), PT(4.5,4.5), 10, sqrt(2.0)/2.0);
	for (int i = 0; i < u.size(); i++) cerr << u[i] << " "; cerr << endl;
	u = CircleCircleIntersection(PT(1,1), PT(4.5,4.5), 5, sqrt(2.0)/2.0);
	for (int i = 0; i < u.size(); i++) cerr << u[i] << " "; cerr << endl;
  
	// area should be 5.0; centroid should be (1.1666666, 1.166666)
	PT pa[] = {PT(0,0), PT(5,0), PT(1,1), PT(0,5)};
	vector<PT> p(pa, pa+4); PT c = ComputeCentroid(p);
	cerr << "Area: " << ComputeArea(p) << endl;
	cerr << "Centroid: " << c << endl;
}