Exemplo n.º 1
0
 def test_constrained_smoothing(self):
     testpath1=[[0, 0], #fix
           [1, 0],
           [2, 0],
           [3, 0],
           [4, 0],
           [5, 0],
           [6, 0], #fix
           [6, 1],
           [6, 2],
           [6, 3], #fix
           [5, 3],
           [4, 3],
           [3, 3],
           [2, 3],
           [1, 3],
           [0, 3], #fix
           [0, 2],
           [0, 1]]
     testfix1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0]
     answer1 = [[0, 0],
                [0.7938620981547201, -0.8311168821106101],
                [1.8579052986461084, -1.3834788165869276],
                [3.053905318597796, -1.5745863173084],
                [4.23141390533387, -1.3784271816058231],
                [5.250184859723701, -0.8264215958231558],
                [6, 0],
                [6.415150091996651, 0.9836951698796843],
                [6.41942442687092, 2.019512290770163],
                [6, 3],
                [5.206131365604606, 3.831104483245191],
                [4.142082497497067, 4.383455704596517],
                [2.9460804122779813, 4.5745592975708105],
                [1.768574219397359, 4.378404668718541],
                [0.7498089205417316, 3.826409771585794],
                [0, 3],
                [-0.4151464728194156, 2.016311854977891],
                [-0.4194207879552198, 0.9804948340550833]]
     
     self.assertAlmostEqual(answer1, hw3.smooth(testpath1, testfix1), 4)
     
     testpath2 = [[0, 0], # fix
                  [2, 0],
                  [4, 0], # fix
                  [4, 2],
                  [4, 4], # fix
                  [2, 4],
                  [0, 4], # fix
                  [0, 2]]
     testfix2 = [1, 0, 1, 0, 1, 0, 1, 0]
     answer2 = [[0, 0],
                [2.0116767115496095, -0.7015439080661671],
                [4, 0],
                [4.701543905420104, 2.0116768147460418],
                [4, 4],
                [1.9883231877640861, 4.701543807525115],
                [0, 4],
                [-0.7015438099112995, 1.9883232808252207]]
     
     self.assertAlmostEqual(answer2, hw3.smooth(testpath2, testfix2), 4)
Exemplo n.º 2
0
    def test_constrained_smoothing(self):
        testpath1 = [
            [0, 0],  #fix
            [1, 0],
            [2, 0],
            [3, 0],
            [4, 0],
            [5, 0],
            [6, 0],  #fix
            [6, 1],
            [6, 2],
            [6, 3],  #fix
            [5, 3],
            [4, 3],
            [3, 3],
            [2, 3],
            [1, 3],
            [0, 3],  #fix
            [0, 2],
            [0, 1]
        ]
        testfix1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0]
        answer1 = [[0, 0], [0.7938620981547201, -0.8311168821106101],
                   [1.8579052986461084, -1.3834788165869276],
                   [3.053905318597796, -1.5745863173084],
                   [4.23141390533387, -1.3784271816058231],
                   [5.250184859723701, -0.8264215958231558], [6, 0],
                   [6.415150091996651, 0.9836951698796843],
                   [6.41942442687092, 2.019512290770163], [6, 3],
                   [5.206131365604606, 3.831104483245191],
                   [4.142082497497067, 4.383455704596517],
                   [2.9460804122779813, 4.5745592975708105],
                   [1.768574219397359, 4.378404668718541],
                   [0.7498089205417316, 3.826409771585794], [0, 3],
                   [-0.4151464728194156, 2.016311854977891],
                   [-0.4194207879552198, 0.9804948340550833]]

        self.assertAlmostEqual(answer1, hw3.smooth(testpath1, testfix1), 4)

        testpath2 = [
            [0, 0],  # fix
            [2, 0],
            [4, 0],  # fix
            [4, 2],
            [4, 4],  # fix
            [2, 4],
            [0, 4],  # fix
            [0, 2]
        ]
        testfix2 = [1, 0, 1, 0, 1, 0, 1, 0]
        answer2 = [[0, 0], [2.0116767115496095, -0.7015439080661671], [4, 0],
                   [4.701543905420104, 2.0116768147460418], [4, 4],
                   [1.9883231877640861, 4.701543807525115], [0, 4],
                   [-0.7015438099112995, 1.9883232808252207]]

        self.assertAlmostEqual(answer2, hw3.smooth(testpath2, testfix2), 4)
Exemplo n.º 3
0
def add_plot(path, fix, plot, label_txt):
    path_xs = map(lambda x: x[0], path)
    path_xs.append(path[0][0])
    path_ys = map(lambda x: x[1], path)
    path_ys.append(path[0][1])
    plot.plot(path_xs, path_ys, label="%s points" % label_txt, linestyle='none', marker='.')
    smoothed = hw3.smooth(path, fix)
    smoothed_xs = map(lambda x: x[0], smoothed)
    smoothed_xs.append(smoothed[0][0])
    smoothed_ys = map(lambda x: x[1], smoothed)
    smoothed_ys.append(smoothed[0][1])
    plot.plot(smoothed_xs, smoothed_ys, label="%s smoothed" % label_txt)