Example #1
0
	vector<double> JointUniversal::getViolation()
	{
		vector<double> out;
		MatNxN s3 = getConstraintViolationS3();
		MatNxN n11 = getConstraintViolationN11a();

		out.push_back(s3(0,0));
		out.push_back(s3(1,0));
		out.push_back(s3(2,0));
		out.push_back(n11(0,0));

		return out;
	}
int main()
{
	ListNode n6(10);
	ListNode n7(3);
	ListNode n8(45);
	ListNode n9(1);
	ListNode n10(38);
	ListNode n11(89);

	n6.next = &n7;
	n7.next = &n8;
	n8.next = &n9;
	n9.next = &n10;
	n10.next = &n11;

	ListNode* n = reverseList(&n6);

	while(n)
	{
		printf("%d->", n->val);
		n = n->next;
	}
    return 0;
}
bool dgCollisionConvexHull::RemoveCoplanarEdge (dgPolyhedra& polyhedra, const dgBigVector* const hullVertexArray) const
{
	bool removeEdge = false;
	// remove coplanar edges
	dgInt32 mark = polyhedra.IncLRU();
	dgPolyhedra::Iterator iter (polyhedra);
	for (iter.Begin(); iter; ) {
		dgEdge* edge0 = &(*iter);
		iter ++;

		if (edge0->m_incidentFace != -1) {

			if (edge0->m_mark < mark) {
				edge0->m_mark = mark;
				edge0->m_twin->m_mark = mark;
				dgBigVector normal0 (FaceNormal (edge0, &hullVertexArray[0]));
				dgBigVector normal1 (FaceNormal (edge0->m_twin, &hullVertexArray[0]));

				dgFloat64 test = normal0.DotProduct(normal1).GetScalar();
				if (test > dgFloat64 (0.99995f)) {

					if ((edge0->m_twin->m_next->m_twin->m_next != edge0) && (edge0->m_next->m_twin->m_next != edge0->m_twin)) {
						#define DG_MAX_EDGE_ANGLE dgFloat32 (1.0e-3f)

						if (edge0->m_twin == &(*iter)) {
							if (iter) {
								iter ++;
							}
						}

						dgBigVector e1 (hullVertexArray[edge0->m_twin->m_next->m_next->m_incidentVertex] - hullVertexArray[edge0->m_incidentVertex]);
						dgBigVector e0 (hullVertexArray[edge0->m_incidentVertex] - hullVertexArray[edge0->m_prev->m_incidentVertex]);

						dgAssert(e0.m_w == dgFloat64(0.0f));
						dgAssert(e1.m_w == dgFloat64(0.0f));
						dgAssert (e0.DotProduct(e0).GetScalar() >= dgFloat64 (0.0f));
						dgAssert (e1.DotProduct(e1).GetScalar() >= dgFloat64 (0.0f));

						e0 = e0.Scale (dgFloat64 (1.0f) / sqrt (e0.DotProduct(e0).GetScalar()));
						e1 = e1.Scale (dgFloat64 (1.0f) / sqrt (e1.DotProduct(e1).GetScalar()));
						dgBigVector n1 (e0.CrossProduct(e1));

						dgFloat64 projection = n1.DotProduct(normal0).GetScalar();
						if (projection >= DG_MAX_EDGE_ANGLE) {

							dgBigVector e11 (hullVertexArray[edge0->m_next->m_next->m_incidentVertex] - hullVertexArray[edge0->m_twin->m_incidentVertex]);
							dgBigVector e00 (hullVertexArray[edge0->m_twin->m_incidentVertex] - hullVertexArray[edge0->m_twin->m_prev->m_incidentVertex]);
							dgAssert (e00.m_w == dgFloat64 (0.0f));
							dgAssert (e11.m_w == dgFloat64 (0.0f));
							dgAssert (e00.DotProduct(e00).GetScalar() >= dgFloat64 (0.0f));
							dgAssert (e11.DotProduct(e11).GetScalar() >= dgFloat64 (0.0f));
							e00 = e00.Scale(dgFloat64(1.0f) / sqrt(e00.DotProduct(e00).GetScalar()));
							e11 = e11.Scale(dgFloat64(1.0f) / sqrt(e11.DotProduct(e11).GetScalar()));

							dgBigVector n11 (e00.CrossProduct(e11));
							projection = n11.DotProduct(normal0).GetScalar();
							if (projection >= DG_MAX_EDGE_ANGLE) {
								dgAssert (&(*iter) != edge0);
								dgAssert (&(*iter) != edge0->m_twin);
								polyhedra.DeleteEdge(edge0);
								removeEdge = true;
							}
						}

					} else {
						dgEdge* next = edge0->m_next;
						dgEdge* prev = edge0->m_prev;
						polyhedra.DeleteEdge(edge0);
						for (edge0 = next; edge0->m_prev->m_twin == edge0; edge0 = next) {
							next = edge0->m_next;
							polyhedra.DeleteEdge(edge0);
						}

						for (edge0 = prev; edge0->m_next->m_twin == edge0; edge0 = prev) {
							prev = edge0->m_prev;
							polyhedra.DeleteEdge(edge0);
						}
						iter.Begin(); 
						removeEdge = true;
					}
				}
			}
		}
	}

	return removeEdge;
}
Example #4
0
void Cone::tesselate( int nTheta, int nHeight,
	std::vector< Vector4f >& positions,
	std::vector< Vector3f >& normals )
{
	positions.clear();
	normals.clear();

	positions.reserve( 6 * nTheta * nHeight );
	normals.reserve( 6 * nTheta * nHeight );

	float dt = MathUtils::TWO_PI / nTheta;
	float dh = height / nHeight;

	Vector4f bc( baseCenter, 0 );

	for( int t = 0; t < nTheta; ++t )
	{
		float t0 = t * dt;
		float t1 = t0 + dt;

		for( int h = 0; h < nHeight; ++h )
		{
			float h0 = h * dh;
			float h1 = h0 + dh;

			float r0 = baseRadius * ( 1 - h0 / height );
			float r1 = baseRadius * ( 1 - h1 / height );

			float x00 = r0 * cosf( t0 );
			float y00 = r0 * sinf( t0 );
			float x10 = r0 * cosf( t1 );
			float y10 = r0 * sinf( t1 );
			float x01 = r1 * cosf( t0 );
			float y01 = r1 * sinf( t0 );
			float x11 = r1 * cosf( t1 );
			float y11 = r1 * sinf( t1 );

			Vector4f v00 = bc + Vector4f( x00, y00, h0, 1 );
			Vector3f n00( x00, y00, r0 / sqrtf( r0 * r0 + h0 * h0 ) );
			n00.normalize();

			Vector4f v10 = bc + Vector4f( x10, y10, h0, 1 );
			Vector3f n10( x10, y10, r0 / sqrtf( r0 * r0 + h0 * h0 ) );
			n10.normalize();

			Vector4f v01 = bc + Vector4f( x01, y01, h1, 1 );
			Vector3f n01( x01, y01, r1 / sqrtf( r1 * r1 + h1 * h1 ) );
			n01.normalize();

			Vector4f v11 = bc + Vector4f( x11, y11, h1, 1 );
			Vector3f n11( x11, y11, r1 / sqrtf( r1 * r1 + h1 * h1 ) );
			n11.normalize();

			positions.push_back( v00 );
			normals.push_back( n00 );
			positions.push_back( v10 );
			normals.push_back( n10 );
			positions.push_back( v01 );
			normals.push_back( n01 );

			positions.push_back( v01 );
			normals.push_back( n01 );
			positions.push_back( v10 );
			normals.push_back( n10 );
			positions.push_back( v11 );
			normals.push_back( n11 );
		}
	}
}
Example #5
0
void Sphere::tesselate( int nTheta, int nPhi,
	std::vector< Vector4f >& positions,
	std::vector< Vector3f >& normals )
{
	positions.clear();
	normals.clear();

	positions.reserve( 6 * nTheta * nPhi );
	normals.reserve( 6 * nTheta * nPhi );

	float dt = MathUtils::TWO_PI / nTheta;
	float dp = MathUtils::PI / nPhi;

	Vector4f c( center, 0 );

	for( int t = 0; t < nTheta; ++t )
	{
		float t0 = t * dt;
		float t1 = t0 + dt;

		for( int p = 0; p < nPhi; ++p )
		{
			float p0 = p * dp;
			float p1 = p0 + dp;

			float x00 = cosf( t0 ) * sinf( p0 );
			float y00 = sinf( t0 ) * sinf( p0 );
			float z00 = cosf( p0 );
			float x10 = cosf( t1 ) * sinf( p0 );
			float y10 = sinf( t1 ) * sinf( p0 );
			float z10 = cosf( p0 );
			float x01 = cosf( t0 ) * sinf( p1 );
			float y01 = sinf( t0 ) * sinf( p1 );
			float z01 = cosf( p1 );
			float x11 = cosf( t1 ) * sinf( p1 );
			float y11 = sinf( t1 ) * sinf( p1 );
			float z11 = cosf( p1 );

			Vector4f v00 = c + Vector4f( radius * x00, radius * y00, radius * z00, 1 );
			Vector3f n00( x00, y00, z00 );
			Vector4f v10 = c + Vector4f( radius * x10, radius * y10, radius * z10, 1 );
			Vector3f n10( x10, y10, z10 );
			Vector4f v01 = c + Vector4f( radius * x01, radius * y01, radius * z01, 1 );
			Vector3f n01( x01, y01, z01 );
			Vector4f v11 = c + Vector4f( radius * x11, radius * y11, radius * z11, 1 );
			Vector3f n11( x11, y11, z11 );

			positions.push_back( v00 );
			normals.push_back( n00 );
			positions.push_back( v10 );
			normals.push_back( n10 );
			positions.push_back( v01 );
			normals.push_back( n01 );

			positions.push_back( v01 );
			normals.push_back( n01 );
			positions.push_back( v10 );
			normals.push_back( n10 );
			positions.push_back( v11 );
			normals.push_back( n11 );
		}
	}
}
Example #6
0
TEST(learnWithBPTest, XOR100)
{
  Entry<double> a;
  Entry<double> b;
  Bias<double> bias1(1);
  Bias<double> bias2(1);
  Neuron<double, LinearActivationFunction<double >> n11(0.1);
  Neuron<double, LinearActivationFunction<double >> n12(0.1);
  Neuron<double, LinearActivationFunction<double >> n22(0.1);
  Exit<double> exit;
  std::vector < Link<double >> links(10);
  //wejścia do 1 neuronu
  a.setLinkOut(&links[0]);
  b.setLinkOut(&links[1]);
  bias1.setLinkOut(&links[2]);
  n11.setLinkIn(&links[2]);
  n11.setLinkIn(&links[0]);
  n11.setLinkIn(&links[1]);
  //wejścia do drugiego neuronu
  a.setLinkOut(&links[3]);
  b.setLinkOut(&links[4]);
  bias1.setLinkOut(&links[5]);
  n12.setLinkIn(&links[5]);
  n12.setLinkIn(&links[3]);
  n12.setLinkIn(&links[4]);
  //połączenia międzyneuronowe
  n11.setLinkOut(&links[6]);
  n12.setLinkOut(&links[7]);
  bias2.setLinkOut(&links[8]);
  n22.setLinkIn(&links[8]);
  n22.setLinkIn(&links[6]);
  n22.setLinkIn(&links[7]);
  //do wyjścia
  n22.setLinkOut(&links[9]);
  bias1.sendBiasToLinks();
  bias2.sendBiasToLinks();
  //n.printWages();
  exit.setLinkIn(&links[9]);

  //uczenie
  for (int i = 0; i < 5000; i++)
  {
    a.setEntry(0);
    b.setEntry(0);
    n11.calculateOutput();
    n12.calculateOutput();
    n22.calculateOutput();
    exit.learn(0);
    n22.propagateAnswer();
    n22.learnDelta();
    n11.learnBP();
    n12.learnBP();
    
    // Qstd::cout<< "0,0: " << exit.getExit() << "\n";
    
    a.setEntry(1);
    b.setEntry(0);
    n11.calculateOutput();
    n12.calculateOutput();
    n22.calculateOutput();
    exit.learn(1);
    n22.propagateAnswer();
    n22.learnDelta();
    n11.learnBP();
    n12.learnBP();
    
    // Qstd::cout<< " 1,0: " << exit.getExit() << "\n";
    
    a.setEntry(0);
    b.setEntry(1);
    n11.calculateOutput();
    n12.calculateOutput();
    n22.calculateOutput();
    exit.learn(1);
    n22.propagateAnswer();
    n22.learnDelta();
    n11.learnBP();
    n12.learnBP();
    
    // Qstd::cout<< " 0,1: " << exit.getExit() << "\n";
    
    a.setEntry(1);
    b.setEntry(1);
    n11.calculateOutput();
    n12.calculateOutput();
    n22.calculateOutput();
    exit.learn(0);
    n22.propagateAnswer();
    n22.learnDelta();
    n11.learnBP();
    n12.learnBP();
    
    // Qstd::cout<< " 1,1: " << exit.getExit() << "\n";
//    for (auto l : links)
//    {
//      // Qstd::cout<< " " << l.getValue();
//    }
//    // Qstd::cout<< "\n";
    
  //n11.printWages();
  //n12.printWages();
  //n22.printWages();
  }
  n11.printWages();
  n12.printWages();
  n22.printWages();
  a.setEntry(0);
  b.setEntry(0);
  n11.calculateOutput();
  n12.calculateOutput();
  n22.calculateOutput();
  ASSERT_GT(0.1, exit.getExit());
  a.setEntry(1);
  b.setEntry(0);
  n11.calculateOutput();
  n12.calculateOutput();
  n22.calculateOutput();
  ASSERT_LT(0.9, exit.getExit());
  a.setEntry(0);
  b.setEntry(1);
  n11.calculateOutput();
  n12.calculateOutput();
  n22.calculateOutput();
  ASSERT_LT(0.9, exit.getExit());
  a.setEntry(1);
  b.setEntry(1);
  n11.calculateOutput();
  n12.calculateOutput();
  n22.calculateOutput();
  ASSERT_GT(0.1, exit.getExit());
}