コード例 #1
0
        public float dot_product(Vector3d vct2)
        {
            // v1->.v2-> = x1*x2 + y1*y2 + z1*z2
            // How to call :
            // Vector3d v1 = new Vector3d(1,0,0);
            // Vector3d v2 = new Vector3d(0,1,0);
            // v1.dot_product(v2) return float 0

            return this.get_x()*vct2.get_x()
                + this.get_y()*vct2.get_y()
                + this.get_z()*vct2.get_z();
        }
コード例 #2
0
        public Vector3d cross_product(Vector3d vct2)
        {
            // How to call :
            // Vector3d v1 = new Vector3d(1,0,0);
            // Vector3d v2 = new Vector3d(0,1,0);
            // v1.cross_product(v2) return Vector3d (0 0 1)

            Vector3d vct = new Vector3d(0,0,0);

            // v1->^v2-> = v->

            // vx = y1 z2 - y2 z1
            vct.set_x( this.get_y() * vct2.get_z() - vct2.get_y() * this.get_z() );

            // vy = z1 x2 - x1 z2
            vct.set_y( this.get_z() * vct2.get_x() - this.get_x() * vct2.get_z() );

            // vz = x1 y2 - y1 x2
            vct.set_z( this.get_x() * vct2.get_y() - this.get_y() * vct2.get_x() );

            return vct;
        }