Zoom in the current code only the 2D, think about it yourself (╯▽╰)
Projection matrix formula: 3D
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceconsoleapplication6{ classmatrix3x3 { Public DoubleM11, M12, M13; Public DoubleM21, M22, M23; Public DoubleM31, M32, M33; #regionScaling Public Staticmatrix3x3 Setupscale (floatKx,floatKy,floatKz) {matrix3x3 m=Newmatrix3x3 (); M.M11= Kx; M.M12 =0; M.M13 =0; M.M11=0; M.M12 = Ky; M.M13 =0; M.M11=0; M.M12 =0; M.M13 =Kz; returnm; } Public Staticmatrix3x3 Setupscale (Vector3 v) {matrix3x3 m=Newmatrix3x3 (); M.M11= v.x; M.M12 =0; M.M13 =0; M.M11=0; M.M12 = V.Y; M.M13 =0; M.M11=0; M.M12 =0; M.M13 =v.z; returnm; } #endregion #regionOrthogonal projection/// <summary> ///projecting to xy,xz,yz one of the planes/// </summary> /// <param name= "axis" >1=xy,2=xz,3=yz</param> Public voidSetupproject (intaxis) { Switch(axis) { Case 1: //XY planeM11 =1; M12 =0; M13 =0; M21=0; M22 =1; M23 =0; M31=0; M32 =0; M33 =0; Break; Case 2: //XZ planeM11 =1; M12 =0; M13 =0; M21=0; M22 =0; M23 =0; M31=0; M32 =0; M33 =1; Break; Case 3: //YZ planeM11 =0; M12 =0; M13 =0; M21=0; M22 =1; M23 =0; M31=0; M32 =0; M33 =1; Break; } } //projecting to any plane Public voidSetupproject (Vector3 v) {M11=1-v.x *v.x; M22=1-V.y *v.y; M33=1-V.z *v.z; M12= M21 =-v.x *v.y; M13= M31 =-v.x *v.z; M23= M32 =-v.y *v.z; } #endregion } classVector3 { Public Doublex, y, Z; PublicVector3 (DoubleXDoubleYDoublez) { This. x =x; This. y =y; This. z =Z; } Public Override stringToString () {return string. Format ("{0} {1} {2}", x, Y, z); } } }
Matrix Scaling and projection