Advertisement
danfalck

arc_center_from_rad_value.py

Jul 23rd, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import math
  2. from FreeCAD import Vector
  3. import Part
  4.  
  5. def calcRadCenter(v1,radius,v2,cw):
  6.     '''
  7.    calculates centerpoint for arc move that uses only radius value
  8.    and is missing I,J,K coords.v1 = start pt of arc,v2 =end pt of arc
  9.    '''
  10.     chord = v2.sub(v1)
  11.     l = Part.makeLine((v1.x,v1.y,v1.z),(v2.x,v2.y,v2.z))
  12.     sagitta = radius-math.sqrt(math.pow(radius,2)- math.pow(l.Length/2.0,2))
  13.     if cw:
  14.         perp = chord.cross(Vector(0,0,1))
  15.     else:    
  16.         perp = chord.cross(Vector(0,0,-1))
  17.     startpoint = v1.add(chord.multiply(0.5))
  18.     perp.normalize()
  19.     centerpt = startpoint.add(perp.multiply(radius-sagitta))
  20.     return centerpt
  21.  
  22. def calcIJK(v1,centerpt):
  23.     '''
  24.    return relative IJK values from a previous point (vector) to the center of an arc
  25.    (also a vector)
  26.    '''
  27.     return centerpt.sub(v1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement