@@ -84,6 +84,7 @@ def func(field, observers):
8484
8585 # with anchor
8686 F ,T = getFT (hom , cloop , anchor = cloop .position )
87+ T *= - 1 #bad sign at initial test design
8788 assert np .amax (abs (F )) < 1e-14
8889 assert abs (T [0 ]) < 1e-14
8990 assert abs (T [1 ] - np .pi ) < 1e-3
@@ -106,6 +107,7 @@ def func(field, observers):
106107
107108 # with anchor
108109 F ,T = getFT (hom , rloop , anchor = rloop .position )
110+ T *= - 1 #bad sign at initial test design
109111 assert np .amax (abs (F )) < 1e-14
110112 assert abs (T [0 ]) < 1e-14
111113 assert abs (T [1 ] + 4 ) < 1e-3
@@ -262,3 +264,32 @@ def test_sphere_cube_at_distance():
262264
263265 assert max (abs (errF )) < 1e-5
264266 assert max (abs (errT )) < 1e-5
267+
268+
269+ def test_torque_sign ():
270+ """ make sure that torque sign is in the right direction"""
271+
272+ # Cuboid -> Cuboid
273+ mag1 = magpy .magnet .Cuboid (position = (2 ,0 ,0 ), polarization = (1 ,0 ,0 ), dimension = (2 ,1 ,1 ))
274+ mag2 = magpy .magnet .Cuboid (position = (- 2 ,0 ,0 ), polarization = (1 ,0 ,0 ), dimension = (2 ,1 ,1 ))
275+
276+ mag1 .rotate_from_angax (15 , "y" )
277+ mag1 .meshing = (3 ,3 ,3 )
278+
279+ _ ,T = getFT (mag2 , mag1 )
280+
281+ assert T [1 ] < 0
282+
283+ # Cuboid -> Polyline
284+ mag = magpy .magnet .Cuboid (polarization = (0 ,0 ,1 ), dimension = (1 ,1 ,2 ))
285+
286+ ts = np .linspace (0 ,2 * np .pi ,10 )
287+ verts = [(2 * np .cos (t ), 2 * np .sin (t ),0 ) for t in ts ]
288+ loop = magpy .current .Polyline (vertices = verts , current = 1 )
289+ loop .rotate_from_angax (15 , "y" )
290+
291+ loop .meshing = 2
292+
293+ _ ,T = getFT (mag , loop , anchor = (0 ,0 ,0 ))
294+
295+ assert T [1 ] < 0
0 commit comments