<commit_before>package etomica.space3d;

import etomica.api.IVector3D;

public class RotationTensor3D extends Tensor3D implements etomica.space.RotationTensor {
    public RotationTensor3D() {super(); reset();}
    public void reset() {
        xx = 1.0; xy = 0.0; xz = 0.0;
        yx = 0.0; yy = 1.0; yz = 0.0;
        zx = 0.0; zy = 0.0; zz = 1.0;
    }

    /**
     * Sets tensor for rotation about the indicated axis (0=x,1=y,2=z) by 
     * the given angle.
     */
    public void setAxial(int i, double theta) {
        double st = Math.sin(theta);
        double ct = Math.cos(theta);
        switch(i) {
            case 0: xx = 1.; xy = 0.; xz = 0.;
                    yx = 0.; yy = ct; yz = -st;
                    zx = 0.; zy = st; zz = ct;
                    return;
            case 1: xx = ct; xy = 0.; xz = -st;
                    yx = 0.; yy = 1.; yz = 0.;
                    zx = st; zy = 0.; zz = ct;
                    return;
            case 2: xx = ct; xy = -st; xz = 0.;
                    yx = st; yy = ct;  yz = 0.;
                    zx = 0.; zy = 0.;  zz = 1.;
                    return;
            default: throw new IllegalArgumentException("Improper axis specified for Space3D.RotationTensor.setAxial");
        }
    }
    /**
     * Not yet implemented.
     */
    public void setAngles(double[] angles) {
        throw new RuntimeException("Space3D.CoordinateGroup.setAngles() not yet implemented");
    }

    public void invert() {
        transpose();
    }

    public void setOrientation(IOrientationFull3D orientation3D) {
        IVector3D direction = (IVector3D)orientation3D.getDirection();
        IVector3D secondaryDirection = (IVector3D)orientation3D.getSecondaryDirection();
        xx = direction.x(0);<commit_msg>add method to set rotation via quaternions<commit_after>package etomica.space3d;

import etomica.api.IVector3D;

public class RotationTensor3D extends Tensor3D implements etomica.space.RotationTensor {
    public RotationTensor3D() {super(); reset();}
    public void reset() {
        xx = 1.0; xy = 0.0; xz = 0.0;
        yx = 0.0; yy = 1.0; yz = 0.0;
        zx = 0.0; zy = 0.0; zz = 1.0;
    }

    /**
     * Sets tensor for rotation about the indicated axis (0=x,1=y,2=z) by 
     * the given angle.
     */
    public void setAxial(int i, double theta) {
        double st = Math.sin(theta);
        double ct = Math.cos(theta);
        switch(i) {
            case 0: xx = 1.; xy = 0.; xz = 0.;
                    yx = 0.; yy = ct; yz = -st;
                    zx = 0.; zy = st; zz = ct;
                    return;
            case 1: xx = ct; xy = 0.; xz = -st;
                    yx = 0.; yy = 1.; yz = 0.;
                    zx = st; zy = 0.; zz = ct;
                    return;
            case 2: xx = ct; xy = -st; xz = 0.;
                    yx = st; yy = ct;  yz = 0.;
                    zx = 0.; zy = 0.;  zz = 1.;
                    return;
            default: throw new IllegalArgumentException("Improper axis specified for Space3D.RotationTensor.setAxial");
        }
    }
    /**
     * Not yet implemented.
     */
    public void setAngles(double[] angles) {
        throw new RuntimeException("Space3D.CoordinateGroup.setAngles() not yet implemented");
    }

    public void invert() {
        transpose();
    }

    public void setQuaternions(double[] q) {
        double q0 = q[0];
        double q1 = q[1];
        double q2 = q[2];
        double q3 = q[3];
        
        // A&T bogus
        xx = q0*q0 + q1*q1 - q2*q2 - q3*q3;
        xy = 2*(q1*q2 + q0*q3);
        xz = 2*(q1*q3 - q0*q2);
        
        yx = 2*(q1*q2 - q0*q3);
        yy = q0*q0 - q1*q1 + q2*q2 - q3*q3;
        yz = 2*(q2*q3 + q0*q1);
        
        zx = 2*(q1*q3 + q0*q2);
        zy = 2*(q2*q3 - q0*q1);
        zz = q0*q0 - q1*q1 - q2*q2 + q3*q3;

        // A&T smoke crack.  this is their matrix, transposed, and xy,yx,yz and zy are negatives of what is in the book.
//        xx = q0*q0 + q1*q1 - q2*q2 - q3*q3;
//        yx = -2*(q1*q2 + q0*q3);
//        zx = 2*(q1*q3 - q0*q2);
//        
//        xy = -2*(q1*q2 - q0*q3);
//        yy = q0*q0 - q1*q1 + q2*q2 - q3*q3;
//        zy = -2*(q2*q3 + q0*q1);
//        
//        xz = 2*(q1*q3 + q0*q2);
//        yz = -2*(q2*q3 - q0*q1);
//        zz = q0*q0 - q1*q1 - q2*q2 + q3*q3;
    }

    public void setOrientation(IOrientationFull3D orientation3D) {
        IVector3D direction = (IVector3D)orientation3D.getDirection();
        IVector3D secondaryDirection = (IVector3D)orientation3D.getSecondaryDirection();
        xx = direction.x(0);
{'fraction_non_alphanumeric': 0.1426397042835399, 'fraction_numerical': 0.049141117634268316, 'mean_word_length': 1.5400331308669244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2961497', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1657, 'n_words': 433}