Ejemplo n.º 1
0
    // Adds a new control point to the arrays CPCenter, CPRight and CPLeft
    private void AddControlPoints(Vector3 ca0, Vector3 ox0, Vector3 ca1, int ss, int handedness)
    {
        Vector3 A, B, C, D, p0, cpt0, cpt1, cpt2;

        A = ca1 - ca0;
        B = ox0 - ca0;

        // Vector normal to the peptide plane (pointing outside in the case of the
        // alpha helix).
        C = Vector3.Cross(A, B);

        // Vector contained in the peptide plane (perpendicular to its direction).
        D = Vector3.Cross(C, A);

        C.Normalize();
        D.Normalize();

        // Flipping test (to avoid self crossing in the strands).
        if ((ss != HELIX) && (90f < Vector3.Angle(flipTestV, D)))
        {
            D = D * -1f;             // flip detected, the plane vector is inverted
        }
        // The central control point is constructed
        cpt0 = LinearComb(0.5f, ca0, 0.5f, ca1);
        splineCenter.SetCPoint(3, cpt0);

        if (ss == HELIX)
        {
            // When residue i is contained in a helix, the control point is moved away
            // from the helix axis, along the C direction.
            p0 = Vector3.zero;
            splineCenter.GetCPoint(3, out p0);
            cpt0 = LinearComb(1f, p0, handedness * HELIX_DIAM, C);
            splineCenter.SetCPoint(3, cpt0);
        }

        // The control points for the side ribbons are constructed.
        cpt1 = LinearComb(1f, cpt0, ribbonWidth[ss], D);
        splineSide1.SetCPoint(3, cpt1);

        cpt2 = LinearComb(1f, cpt0, -ribbonWidth[ss], D);
        splineSide2.SetCPoint(3, cpt2);


        // Saving the plane vector (for the flipping test in the next call)
        flipTestV = D;
    }     // End of AddControlPoints