Ejemplo n.º 1
0
__CD__BEGIN

Vector3D my_tri_tri_intersect(const Triangle& t1, const Triangle& t2)
{
    Plane p1(t1.v1,t1.v2,t1.v3);
    int other_side=0;
    {
        float f1=p1.Classify(t2.v1);
        float f2=p1.Classify(t2.v2);
        float f3=p1.Classify(t2.v3);
        float f12=f1*f2;
        float f23=f2*f3;
        if (f12>0.0f && f23>0.0f) return Vector3D::Zero;
        other_side=(f12<0.0f?(f23<0.0f?1:0):2);
    }
    Plane p2(t2.v1,t2.v2,t2.v3);
    Vector3D n12(p1.normal+p2.normal);
    TriangleDesc td2(t2,p2);
    const Vector3D& a2=td2[other_side+1];
    const Vector3D& b2=td2[other_side];
    const Vector3D& c2=td2[other_side+2];
    float t21=-(p1.d+p2.d+a2*n12)/((b2-a2)*n12);
    TriangleDesc td1(t1,p1);
    Vector3D P21(a2+t21*(b2-a2));
    if (td1.pointInTri(P21)) return P21;
    float t22=-(p1.d+p2.d+c2*n12)/((b2-c2)*n12);
    Vector3D P22(c2+t22*(b2-c2));
    if (td1.pointInTri(P22)) return P22;

    {
        float f1=p2.Classify(t1.v1);
        float f2=p2.Classify(t1.v2);
        float f3=p2.Classify(t1.v3);
        float f12=f1*f2;
        float f23=f2*f3;
        if (f12>0.0f && f23>0.0f) return Vector3D::Zero;
        other_side=(f12<0.0f?(f23<0.0f?1:0):2);
    }
    const Vector3D& a1=td1[other_side+1];
    const Vector3D& b1=td1[other_side];
    const Vector3D& c1=td1[other_side+2];
    float t11=-(p1.d+p2.d+a1*n12)/((b1-a1)*n12);
    Vector3D P11(a1+t11*(b1-a1));
    if (td2.pointInTri(P11)) return P11;
    float t12=-(p1.d+p2.d+c1*n12)/((b1-c1)*n12);
    Vector3D P12(c1+t12*(b1-c1));
    if (td2.pointInTri(P12)) return P12;
    return Vector3D::Zero;
}
Ejemplo n.º 2
0
  // Calculate the torsion angle between four atoms
  Angle calculateTorsionAngle(const Atom& a1, const Atom& a2, const Atom& a3, const Atom& a4)
		throw(Exception::IllegalPosition)
	{
		Vector3 a12(a2.getPosition() - a1.getPosition());
Vector3 a23(a3.getPosition() - a2.getPosition());
		Vector3 a34(a4.getPosition() - a3.getPosition());

		Vector3 n12(a12 % a23);
		Vector3 n34(a23 % a34);

		if (n12 == Vector3::getZero() ||
				n34 == Vector3::getZero())
		{
			throw(Exception::IllegalPosition(__FILE__, __LINE__, 0, 0, 0));
		}

		n12.normalize();
		n34.normalize();

		Vector3 cross_n12_n34(n12 % n34);
		float direction = cross_n12_n34 * a23;
		float scalar_product = n12 * n34;

		if (scalar_product > 1.0)
		{
			scalar_product = 1.0;
		}
		if (scalar_product < -1.0)
		{
			scalar_product = -1.0;
		}
		Angle a(acos(scalar_product));

		if (direction < 0.0)
		{
			a = -1.0 * (float)a;
		}

		return a;
	}
Ejemplo n.º 3
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());
}