~freecad-community/freecad-extras/assembly2

« back to all changes in this revision

Viewing changes to lib3D.py

  • Committer: looooo
  • Date: 2017-04-29 20:07:18 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: git-v1:9bd1d0d2839baa3c630b3208578efb8243a8e19a
py3: change <> to !=

Show diffs side-by-side

added added

removed removed

Lines of Context:
251
251
    eigErrors = abs(w -1) #errors from 1+0j
252
252
    i = (eigErrors == min(eigErrors)).tolist().index(True)
253
253
    axis = numpy.real(v[:,i])
254
 
    if i <> 1:
 
254
    if i != 1:
255
255
        angle = arccos2(  numpy.real( w[1] ) )
256
256
    else:
257
257
        angle = arccos2(  numpy.real( w[0] ) )
338
338
    u2_x, u2_y, u2_z = u2
339
339
 
340
340
    if numpy.array_equal( u1, u2 ) or numpy.array_equal( u1, -u2 ): #then
341
 
        assert numpy.linalg.norm( u1 ) <> 0
 
341
        assert numpy.linalg.norm( u1 ) != 0
342
342
        # generated using sympy 
343
343
        # > t, p1_x, p1_y, p1_z, p2_x, p2_y, p2_z, u1_x, u1_y, u1_z = symbols('t, p1_x, p1_y, p1_z, p2_x, p2_y, p2_z, u1_x, u1_y, u1_z')
344
344
        # > d_sqrd = (p1_x + u1_x*t - p2_x)**2 + (p1_y + u1_y*t - p2_y)**2  + (p1_z + u1_z*t - p2_z)**2
382
382
    # > t, p1_x, p1_y, p1_z, p2_x, p2_y, p2_z, u1_x, u1_y, u1_z = symbols('t, p1_x, p1_y, p1_z, p2_x, p2_y, p2_z, u1_x, u1_y, u1_z')
383
383
    # > d_sqrd = (p1_x + u1_x*t - p2_x)**2 + (p1_y + u1_y*t - p2_y)**2  + (p1_z + u1_z*t - p2_z)**2
384
384
    # > solve( diff( d_sqrd, t ), t ) # gives the expresssion for t_opt
385
 
    assert numpy.linalg.norm( u1 ) <> 0
 
385
    assert numpy.linalg.norm( u1 ) != 0
386
386
    p1_x, p1_y, p1_z = p1
387
387
    u1_x, u1_y, u1_z = u1
388
388
    #if not (u1_x**2 + u1_y**2 + u1_z**2) == 1:
389
 
    #    raise ValueError, "(u1_x**2 + u1_y**2 + u1_z**2) <>1 but rather %f  " % ( u1_x**2 + u1_y**2 + u1_z**2 )
 
389
    #    raise ValueError, "(u1_x**2 + u1_y**2 + u1_z**2) !=1 but rather %f  " % ( u1_x**2 + u1_y**2 + u1_z**2 )
390
390
    dist = 0
391
391
    for axis2_t in [-10, 0, 10]: #find point on axis 1 which is closest
392
392
        p2_x, p2_y, p2_z = p2 + axis2_t*u2
396
396
    return dist
397
397
 
398
398
def distance_between_axis_and_point( p1,u1,p2 ):
399
 
    assert numpy.linalg.norm( u1 ) <> 0
 
399
    assert numpy.linalg.norm( u1 ) != 0
400
400
    d = p2 - p1
401
401
    offset = d - dotProduct(u1,d)*u1
402
402
    #print(norm(offset))
403
403
    return norm(offset)
404
404
 
405
405
def distance_between_axis_and_point_old( p1, u1, p2 ):
406
 
    assert numpy.linalg.norm( u1 ) <> 0
 
406
    assert numpy.linalg.norm( u1 ) != 0
407
407
    p1_x, p1_y, p1_z = p1
408
408
    u1_x, u1_y, u1_z = u1
409
409
    p2_x, p2_y, p2_z = p2
438
438
    A_matrixs = []
439
439
    for i in range(3):
440
440
        A_matrixs.append([ 
441
 
                [v[j] for j in range(3) if j <> i],
442
 
                [v_ref[j] for j in range(3) if j <> i]] )
 
441
                [v[j] for j in range(3) if j != i],
 
442
                [v_ref[j] for j in range(3) if j != i]] )
443
443
        #prettyPrintArray( A_matrixs[-1] )
444
444
    cond_number = map( numpy.linalg.cond,  A_matrixs)
445
445
    minloc = cond_number.index(min(cond_number)) 
583
583
        axis, angle = testcase
584
584
        q_1, q_2, q_3, q_0  = quaternion(angle, *axis)
585
585
        axis_out, angle_out = quaternion_to_axis_and_angle(q_1, q_2, q_3, q_0)
586
 
        if numpy.sign( angle_out ) <> numpy.sign( angle):
 
586
        if numpy.sign( angle_out ) != numpy.sign( angle):
587
587
            angle_out = -angle_out
588
588
            axis_out = -axis_out
589
589
        if norm(axis - axis_out) > 10**-12 or norm(angle - angle_out) > 10**-9: