Ejemplo n.º 1
0
def check_ifCollinear(axisa, axisb, dbg=False):
    '''
    check if 2 axes are collinear
    '''
    #shift edges to the origin and normalize them
    #move vectors to origin and normalize
    axis1 = FreeCAD.Axis(axisa)
    axis2 = FreeCAD.Axis(axisb)
    if check_ifCoincident(axis1.Base, axis2.Base):
        #same base, if parallel the axis are collinear
        if check_ifParallel(axis1, axis2):
            return True
        else:
            return False
    baseMove = SystemOrigin.sub(axis1.Base)
    axis1.Base = SystemOrigin
    axis2.move(baseMove)
    axis1.Direction = axis1.Direction.normalize()  #useless?
    axis2.Direction = axis2.Direction.normalize()  #useless?
    axis3 = FreeCAD.Axis()
    axis3.Direction = axis2.Base  #create an axis with direction base1 to base2

    if check_ifParallel(axis1, axis3) and check_ifParallel(axis2, axis3):
        return True
    else:
        return False
Ejemplo n.º 2
0
def make_planeNormal(axisa, dbg=False):
    '''
    create a plane normal to the given axis, return the 2 axis which define that plane
    '''
    axis1 = copynorm_AxisToOrigin(axisa)

    planenormal = Part.makePlane(1.0, 1.0, axis1.Base, axis1.Direction)
    freeAx1 = FreeCAD.Axis()
    freeAx2 = FreeCAD.Axis()
    freeAx1.Direction = FreeCAD.Vector(planenormal.Vertexes[2].Point)
    freeAx2.Direction = FreeCAD.Vector(planenormal.Vertexes[1].Point)
    return [copynorm_AxisToOrigin(freeAx1), copynorm_AxisToOrigin(freeAx2)]
Ejemplo n.º 3
0
def make_planeNormal(axisa, dbg=False):
    axis1 = copynorm_AxisToOrigin(axisa)

    planenormal = Part.makePlane(1.0, 1.0, axis1.Base, axis1.Direction)
    freeAx1 = FreeCAD.Axis()
    freeAx2 = FreeCAD.Axis()
    freeAx1.Direction = FreeCAD.Vector(planenormal.Vertexes[2].Point)
    freeAx2.Direction = FreeCAD.Vector(planenormal.Vertexes[1].Point)
    if dbg:
        print planenormal.Vertexes[0].Point, planenormal.Vertexes[
            1].Point, planenormal.Vertexes[2].Point, planenormal.Vertexes[
                3].Point
    return [freeAx1, freeAx2]
Ejemplo n.º 4
0
def cleanAxis(axisa):
    axis = FreeCAD.Axis(axisa)
    axis.Base = zeroIfLessThanTol(axis.Base)
    try:
        axis.Direction.normalize()
    except:
        pass
    axis.Direction = zeroIfLessThanTol(axis.Direction)
    return axis
Ejemplo n.º 5
0
def copynorm_AxisToOrigin(axisa, dbg=False):
    _offset = SystemOrigin.sub(axisa.Base)
    axisb = FreeCAD.Axis(axisa)
    if dbg: print axisa, axisb
    axisb.move(_offset)
    if dbg: print axisa, axisb
    #axisb.Base = SystemOrigin
    axisb.Direction = axisb.Direction.normalize()
    return axisb
Ejemplo n.º 6
0
def normal_2Axis(axisa, axisb, dbg=False):
    #move vectors to origin and normalize
    axis1 = copynorm_AxisToOrigin(axisa)
    axis2 = copynorm_AxisToOrigin(axisb)

    #create an axis with base at SystemOrigin
    axisN = FreeCAD.Axis()
    #set the right direction
    axisN.Direction = axis1.Direction.cross(axis2.Direction)
    if dbg: print axis1, axis2, axisN
    return axisN
Ejemplo n.º 7
0
def normal_2Axis(axisa, axisb, dbg=False):
    '''
    create an axis which is normal to the plane defined by given 2 axes as argument
    '''
    #move vectors to origin and normalize
    axis1 = copynorm_AxisToOrigin(axisa)
    axis2 = copynorm_AxisToOrigin(axisb)
    #create an axis with base at SystemOrigin
    axisN = FreeCAD.Axis()
    #set the right direction
    axisN.Direction = axis1.Direction.cross(axis2.Direction)
    return cleanAxis(axisN)
Ejemplo n.º 8
0
def create_Axis2Points(_start, _end):
    axis = FreeCAD.Axis()
    axis.Base = _start
    axis.Direction = _end.sub(_start)
    #axis.Direction = _end
    return axis
Ejemplo n.º 9
0
def create_Axis(_base, _direction):
    axis = FreeCAD.Axis()
    axis.Base = _base
    axis.Direction = _direction
    return axis
Ejemplo n.º 10
0
def copynorm_AxisToOrigin(axisa, dbg=False):
    offset = SystemOrigin.sub(axisa.Base)
    axisb = FreeCAD.Axis(axisa)
    axisb.Base = SystemOrigin
    return cleanAxis(axisb)
Ejemplo n.º 11
0
from PySide import QtGui, QtCore

from a2p_translateUtils import *
'''
Library that defines the DOF of a Rigid, each rigids has several dependencies which define a refPoint(cross point the the axis)
and a refAxisEnd which is a vector that defines the direction, togeher we can define an axis used in the constraint.

This code was possible only after the reading of the Hamish's code on His wonderful Assembly2 Workbench for FreeCAD
This code was possible only after the reading of the code of the wonderful WorkFeature Macro for FreeCAD
This code was possible only after the reading of Wikipedia pages on vector math

'''
#define some reference axis
SystemOrigin = FreeCAD.Vector(0.0, 0.0, 0.0)

SystemXAxis = FreeCAD.Axis()
SystemXAxis.Base = SystemOrigin
SystemXAxis.Direction = SystemXAxis.Direction.add(FreeCAD.Vector(
    1.0, 0.0, 0.0))

SystemYAxis = FreeCAD.Axis()
SystemYAxis.Base = SystemOrigin
SystemYAxis.Direction = SystemYAxis.Direction.add(FreeCAD.Vector(
    0.0, 1.0, 0.0))

SystemZAxis = FreeCAD.Axis()
SystemZAxis.Base = SystemOrigin
SystemZAxis.Direction = SystemZAxis.Direction.add(FreeCAD.Vector(
    0.0, 0.0, 1.0))

#at the beginning each rigid is able to move along and around all six DOF
Ejemplo n.º 12
0
import FreeCAD, FreeCADGui, Part
from FreeCAD import Base
from PySide import QtGui, QtCore
'''
Library that defines the DOF of a Rigid, each rigids has several dependencies which define a refPoint(cross point the the axis)
and a refAxisEnd which is a vector that defines the direction, togeher we can define an axis used in the constraint.

This code was possible only after the reading of the Hamish's code on His wonderful Assembly2 Workbench for FreeCAD
This code was possible only after the reading of the code of the wonderful WorkFeature Macro for FreeCAD
This code was possible only after the reading of Wikipedia pages on vector math

'''
#define some reference axis
SystemOrigin = FreeCAD.Vector(0.0, 0.0, 0.0)

SystemXAxis = FreeCAD.Axis()
SystemXAxis.Base = SystemOrigin
SystemXAxis.Direction = SystemXAxis.Direction.add(FreeCAD.Vector(
    1.0, 0.0, 0.0))

SystemYAxis = FreeCAD.Axis()
SystemYAxis.Base = SystemOrigin
SystemYAxis.Direction = SystemYAxis.Direction.add(FreeCAD.Vector(
    0.0, 1.0, 0.0))

SystemZAxis = FreeCAD.Axis()
SystemZAxis.Base = SystemOrigin
SystemZAxis.Direction = SystemZAxis.Direction.add(FreeCAD.Vector(
    0.0, 0.0, 1.0))

#at the beginning each rigid is able to move along and around all six DOF