def test_rotate(self):
     v1 = np.array([0, 0, -1])
     v1.reshape(-1, 1)
     genome = np.array([0, 0, 0, math.pi/2, 0])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(v2[0], 0, 5)
     self.assertAlmostEqual(v2[1], 1, 5)
     self.assertAlmostEqual(v2[2], 0, 5)
     genome = np.array([0, 0, 0, 0, math.pi/2])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(v2[0], 0, 5)
     self.assertAlmostEqual(v2[1], 0, 5)
     self.assertAlmostEqual(v2[2], -1, 5)
     genome = np.array([0, 0, 0, 0, math.pi*2.5])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(v2[0], 0, 5)
     self.assertAlmostEqual(v2[1], 0, 5)
     self.assertAlmostEqual(v2[2], -1, 5)
     genome = np.array([0, 0, 0, math.pi/2, math.pi])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(v2[0], 0, 5)
     self.assertAlmostEqual(v2[1], -1, 5)
     self.assertAlmostEqual(v2[2], 0, 5)
     genome = np.array([0, 0, 0, math.pi/2, math.pi*1.5])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(v2[0], 1, 5)
     self.assertAlmostEqual(v2[1], 0, 5)
     self.assertAlmostEqual(v2[2], 0, 5)
     genome = np.array([0, 0, 0, math.pi/2, math.pi*2.5])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(v2[0], -1, 5)
     self.assertAlmostEqual(v2[1], 0, 5)
     self.assertAlmostEqual(v2[2], 0, 5)
     genome = np.array([0, 0, 0, math.pi/2, math.pi/2])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(v2[0], -1, 5)
     self.assertAlmostEqual(v2[1], 0, 5)
     self.assertAlmostEqual(v2[2], 0, 5)
     v1 = np.array([0, 0, -1])
     v1.reshape(-1, 1)
     genome = np.array([0, 0, 0, math.pi/2, math.pi/4])
     v2 = v1.dot(FitnessFunction.rotate(genome))
     self.assertAlmostEqual(FitnessFunction.angle(v2, np.array([-1, 1, 0])), 0, 5)
     it = 1.0
     for x in range(0,int(it*math.pi)):
         for y in range(0,int(it*math.pi)):
             genome = np.array([0,0,0,y/it,x/it])
             v2 = v1.dot(FitnessFunction.rotate(genome))
             self.assertAlmostEqual(np.sqrt(v2.dot(v2)),1,5)
 def test_plot_rotation(self):
     c = Camera(0.48271098732948303, 1920, 1080, [5, 0, 0], [math.pi / 2, 0, math.pi])
     genome = np.array([5, 0, 0, math.pi / 2, 0, math.pi])
     t = Person('Max Mustermann', np.array([0, 0, 0]), 1,
         np.array([0.7, -0.2, 0]), np.array([0.7, 0.2, 0]))
     lt = Person('Agnes Angeschaute', np.array([2, 0, 0]), 1,
         np.array([1.3, -0.2, 0]), np.array([1.3, 0.2, 0]))
     persons = [t, lt]
     #PositionProcess.optimizeAllShots(t, t, c, [t], [], genome, [2])
     snapshot = SceneSnapshot(t, lt, c, persons, [], [], [2])
     optimizer = PositionProcess.CameraOptimizer(snapshot, 2)
     #optimizer.fitness(genome)
     winkel = arange(-math.pi, math.pi, 0.01)
     s = arange(-math.pi, math.pi, 0.01)
     startposition = np.array([5, 0, 0])
     #startposition.reshape(-1, 1)
     for i in range(0, len(winkel)):
         p = startposition.dot(FitnessFunction.rotate(np.array([0, 0, 0, math.pi / 2, winkel[i]])))
         s[i] = FitnessFunction.fitness(np.array([p[0],p[1],p[2],math.pi/2,winkel[i]+0.5*math.pi]), optimizer)
         #s[i] = optimizer.fitness(np.array([5,0,0,math.pi/2,winkel[i]+math.pi/2]))
         #s[i] = optimizer.getPersonQuality(np.array([p[0],p[1],p[2], math.pi / 2, winkel[i] + math.pi/2]), t, 1.2,
         #    personFitnessByImage, occultationWeight)
         #s[i] = optimizer.getPersonQuality(np.array([5,0,0, math.pi / 2, winkel[i] + math.pi/2]), t, 1.2,
         #    personFitnessByImage, occultationWeight)
         #s[i] = PositionProcess.getImageAngles(np.array([p[0],p[1],p[2], math.pi / 2, winkel[i] + math.pi*0.5]), t)[0]
         #s[i] = PositionProcess.getImageAngles(np.array([5,0,0,winkel[i]+math.pi / 2, math.pi/2]), t)[0]
     ax = subplot(111)
     ax.plot(winkel, s)
     ax.grid(True)
     ticklines = ax.get_xticklines()
     ticklines.extend(ax.get_yticklines())
     gridlines = ax.get_xgridlines()
     gridlines.extend(ax.get_ygridlines())
     ticklabels = ax.get_xticklabels()
     ticklabels.extend(ax.get_yticklabels())
     for line in ticklines:
         line.set_linewidth(3)
     for line in gridlines:
         line.set_linestyle('-')
     for label in ticklabels:
         label.set_color('r')
         label.set_fontsize('medium')
     show()