예제 #1
0
    def tangentAt(self, locationVector=None):
        """
        Compute tangent vector at the specified location.
        :param locationVector: location to use. Use the center point if None
        :return: tangent vector
        """

        curve = self._geomAdaptor()

        if locationVector:
            raise NotImplementedError
        else:
            umin, umax = curve.FirstParameter(), curve.LastParameter()
            umid = 0.5 * (umin + umax)

        # TODO what are good parameters for those?
        curve_props = BRepLProp_CLProps(curve, 2, curve.Tolerance())
        curve_props.SetParameter(umid)

        if curve_props.IsTangentDefined():
            dir_handle = gp_Dir(
            )  # this is awkward due to C++ pass by ref in the API
            curve_props.Tangent(dir_handle)

            return Vector(dir_handle)
예제 #2
0
class DiffGeomCurve(object):
    def __init__(self, instance):
        self.instance = instance
        from OCC.BRepLProp import BRepLProp_CLProps
        # initialize with random parameter: 0
        self._curvature = BRepLProp_CLProps(self.instance.adaptor, 0, 2, self.instance.tolerance)

    def curvature(self, u, n, resolution=1e-7):
        self._curvature.SetParameter(u)

    def radius(self, u):
        '''returns the radius at u
        '''
        # NOT SO SURE IF THIS IS THE SAME THING!!!
        self._curvature.SetParameter(u)
        pnt = gp_Pnt()
        self._curvature.CentreOfCurvature(pnt)
        return pnt

    def curvature(self, u):
        # TODO: find a better way to achieve this method
        self._curvature.SetParameter(u)
        return self._curvature.Curvature()

    def tangent(self, u ):
        '''sets or gets ( iff vector ) the tangency at the u parameter
        tangency can be constrained so when setting the tangency, you're constrainting it in fact
        '''
        self._curvature.SetParameter(u)
        if self._curvature.IsTangentDefined():
            direction = gp_Dir()
            self._curvature.Tangent(direction)
            return ddd
        else:
            raise ValueError('no tangent defined')

    def normal(self, u):
        '''returns the normal at u
        '''
        try:
            self._curvature.SetParameter(u)
            ddd = gp_Dir()
            self._curvature.Normal(ddd)
            return ddd
        except:
            raise ValueError('no normal was found')

    def derivative(self, u, n):
        '''
        returns n derivatives at parameter b
        '''
        self._curvature.SetParameter(u)
        deriv = {1:self._curvature.D1,
                 2:self._curvature.D2,
                 3:self._curvature.D3,
                 }
        try:
            return deriv[n]
        except KeyError:
            raise AssertionError, 'n of derivative is one of [1,2,3]'

    def points_from_tangential_deflection(self):
        from OCC.GCPnts import GCPnts_TangentialDeflection
        pass