public static DMatrixRMaj approximateRotationMatrix( DMatrixRMaj orig, DMatrixRMaj R ) {
    """
	<p>
	Finds a rotation matrix which is the optimal approximation to an arbitrary 3 by 3 matrix. Optimality
	is specified by the equation below:<br>
	<br>
	min ||R-Q||<sup>2</sup><sub>F</sub><br>
	R<br>
	where R is the rotation matrix and Q is the matrix being approximated.
	</p>
	<p/>
	<p>
	The technique used is based on SVD and is described in Appendix C of "A Flexible New Technique for
	Camera Calibration" Technical Report, updated 2002.
	</p>
	<p/>
	<p>
	Both origin and R can be the same instance.
	</p>
	
	@param orig Input approximate rotation matrix.  Not modified.
	@param R (Optional) Storage for the approximated rotation matrix.  Modified.
	@return Rotation matrix
    """
		R = checkDeclare3x3( R );

		SingularValueDecomposition<DMatrixRMaj> svd =
				DecompositionFactory_DDRM.svd( orig.numRows, orig.numCols ,true,true,false);

		if( !svd.decompose( orig ) )
			throw new RuntimeException( "SVD Failed" );

		CommonOps_DDRM.mult( svd.getU( null,false ), svd.getV( null,true ), R );

		// svd does not guarantee that U anv V have positive determinants.
		double det = CommonOps_DDRM.det( R );

		if( det < 0 )
			CommonOps_DDRM.scale( -1, R );

		return R;
	}
public static DMatrixRMaj approximateRotationMatrix( DMatrixRMaj orig, DMatrixRMaj R ) {
		R = checkDeclare3x3( R );

		SingularValueDecomposition<DMatrixRMaj> svd =
				DecompositionFactory_DDRM.svd( orig.numRows, orig.numCols ,true,true,false);

		if( !svd.decompose( orig ) )
			throw new RuntimeException( "SVD Failed" );

		CommonOps_DDRM.mult( svd.getU( null,false ), svd.getV( null,true ), R );

		// svd does not guarantee that U anv V have positive determinants.
		double det = CommonOps_DDRM.det( R );

		if( det < 0 )
			CommonOps_DDRM.scale( -1, R );

		return R;
	}
public static DMatrixRMaj approximateRotationMatrix ( DMatrixRMaj orig , DMatrixRMaj R ) { R = checkDeclare3x3 ( R ) ; SingularValueDecomposition < DMatrixRMaj > svd = DecompositionFactory_DDRM . svd ( orig . numRows , orig . numCols , true , true , false ) ; if ( ! svd . decompose ( orig ) ) throw new RuntimeException ( "SVD Failed" ) ; CommonOps_DDRM . mult ( svd . getU ( null , false ) , svd . getV ( null , true ) , R ) ; // svd does not guarantee that U anv V have positive determinants. double det = CommonOps_DDRM . det ( R ) ; if ( det < 0 ) CommonOps_DDRM . scale ( - 1 , R ) ; return R ; }
<p>
Finds a rotation matrix which is the optimal approximation to an arbitrary 3 by 3 matrix. Optimality
is specified by the equation below:<br>
<br>
min ||R-Q||<sup>2</sup><sub>F</sub><br>
R<br>
where R is the rotation matrix and Q is the matrix being approximated.
</p>
<p/>
<p>
The technique used is based on SVD and is described in Appendix C of "A Flexible New Technique for
Camera Calibration" Technical Report, updated 2002.
</p>
<p/>
<p>
Both origin and R can be the same instance.
</p>

@param orig Input approximate rotation matrix.  Not modified.
@param R (Optional) Storage for the approximated rotation matrix.  Modified.
@return Rotation matrix
<p > Finds a rotation matrix which is the optimal approximation to an arbitrary 3 by 3 matrix . Optimality is specified by the equation below : <br > <br > min ||R - Q||<sup > 2< / sup > <sub > F< / sub > <br > R<br > where R is the rotation matrix and Q is the matrix being approximated . < / p > <p / > <p > The technique used is based on SVD and is described in Appendix C of A Flexible New Technique for Camera Calibration Technical Report updated 2002 . < / p > <p / > <p > Both origin and R can be the same instance . < / p >