示例#1
0
 def test_normalize(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         c = random.random() + i
         self.assertTrue(
             BaseUtils.equal(P3(a, b, c).normalize().length(), 1.0))
示例#2
0
    def test_tr_01(self):
        t = (Trajectory(StraightLine2(2.0, P2(1, 0), P2(0, 0))).add_arc_line(
            0.95, False, 22.5).add_strait_line(1.5).add_arc_line(
                0.95, False, 22.5).add_strait_line(2.0 + 2.2).add_arc_line(
                    0.95, True, 67.5).add_strait_line(1.5).add_arc_line(
                        0.95, True, 67.5).add_strait_line(2.2))

        self.assertTrue(BaseUtils.equal(t.direct_at_end(), P2(0, -1)))
示例#3
0
 def test_change_length(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         c = random.random() + i
         d = random.random() + i
         self.assertTrue(
             BaseUtils.equal(P3(a, b, c).change_length(d).length(), d))
示例#4
0
 def test_length(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         c = random.random() + i
         self.assertTrue(
             BaseUtils.equal(
                 P3(a, b, c).length(), float(np.sqrt(a**2 + b**2 + c**2))))
示例#5
0
 def test_mul2(self):
     for i in range(100):
         a = random.random() + i + 1
         b = random.random() + i + 1
         c = random.random() + i + 1
         d = random.random() + i + 1
         self.assertTrue(
             BaseUtils.equal(P2(a, b) * P2(c, d),
                             a * c + b * d,
                             msg="error"))
示例#6
0
 def test_mul2(self):
     for i in range(100):
         a = random.random() + i + 1
         b = random.random() + i + 1
         c = random.random() + i + 1
         d = random.random() + i + 1
         e = random.random() + i + 1
         f = random.random() + i + 1
         self.assertTrue(
             BaseUtils.equal(P3(a, b, e) * P3(c, d, f),
                             a * c + b * d + e * f,
                             msg="error"))
示例#7
0
    def test_angle_to(self):
        for i in range(100):
            a0 = random.random() * np.pi * 1.9 + 1e-6
            b0 = random.random() * np.pi * 1.9 + 1e-6
            a = max(a0, b0)
            b = min(a0, b0)
            p1 = P2(1.0)
            p2 = P2(1.0)

            p1 = p1.rotate(a)
            p2 = p2.rotate(b)

            diff = a - b

            # print(p1.angle_to(p2),diff)

            self.assertTrue(
                BaseUtils.equal(
                    p2.angle_to(p1),
                    diff  #if diff >0 else 2 * np.pi - diff
                ))
示例#8
0
 def test_p2_copy(self):
     for i in range(100):
         p = P2(random.random() + i, random.random() + i)
         self.assertTrue(BaseUtils.equal(p, p.copy()))
         self.assertFalse(p is p.copy())
示例#9
0
 def test_p2_norm(self):
     p = P2(1, 1)
     self.assertTrue(
         BaseUtils.equal(p.normalize(), P2(np.sqrt(2) / 2,
                                           np.sqrt(2) / 2)))
示例#10
0
 def test_p2_len(self):
     p = P2(1, 1)
     self.assertTrue(BaseUtils.equal(p.length(), np.sqrt(2)))
示例#11
0
 def test_straight(self):
     s = StraightLine2(1, np.array([1.0, 1.0]), np.array([0.0, 0.0]))
     self.assertTrue(BaseUtils.equal(s.get_length(), 1))
示例#12
0
 def test_equal2(self):
     BaseUtils.equal(P2(), P2(1e-10), msg="不相等")
     with self.assertRaises(AssertionError):
         BaseUtils.equal(P2(), P2(1e-5), msg="不相等")
示例#13
0
 def test_equal(self):
     BaseUtils.equal(1, 1, msg="不相等")
     with self.assertRaises(AssertionError):
         BaseUtils.equal(1, 2, msg="不相等")
示例#14
0
 def test_angle_to_x_axis(self):
     for i in range(100):
         phi = random.random() * np.pi * 1.9 + 1e-6
         p = P2(1.0)
         p = p.rotate(phi)
         self.assertTrue(BaseUtils.equal(p.angle_to_x_axis(), phi))
示例#15
0
 def test_p2_rotate(self):
     for phi in np.linspace(0.1, 2 * np.pi * 0.99, 100):
         p = P2(1.0)
         p = p.rotate(phi)
         self.assertTrue(BaseUtils.equal(p.angle_to_x_axis(), phi))
示例#16
0
    MM,
)

cct = CCT(
    LocalCoordinateSystem.global_coordinate_system(),
    0.95,
    83 * MM + 15 * MM * 2,
    67.5,
    [30.0, 80.0, 90.0, 90.0],
    128,
    -9664,
    P2(0, 0),
    P2(128 * np.pi * 2, 67.5 / 180.0 * np.pi),
)

# Plot2.plot_cct(cct)
# Plot3.plot_cct(cct)

# Plot2.show()
# Plot3.show()


m = cct.magnetic_field_at(P3())

print(m)

import time
s = time.time()
for p in BaseUtils.linspace(P3(),P3(y=2),500):
    print(cct.magnetic_field_at(p))
print(time.time()-s)