/// <summary>Sets the value of this vector to the normalization of vector v1.</summary> /// <remarks>Sets the value of this vector to the normalization of vector v1.</remarks> /// <param name="v1">the un-normalized vector</param> public void Normalize(Vector4f v1) { float norm; norm = (float)(1.0 / Math.Sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z + v1.w * v1 .w)); this.x = v1.x * norm; this.y = v1.y * norm; this.z = v1.z * norm; this.w = v1.w * norm; }
/// <summary>Constructs and initializes a Vector4f from the specified Vector4f.</summary> /// <remarks>Constructs and initializes a Vector4f from the specified Vector4f.</remarks> /// <param name="v1">the Vector4f containing the initialization x y z w data</param> public Vector4f(Vector4f v1) : base(v1) { }
/// <summary>returns the dot product of this vector and v1</summary> /// <param name="v1">the other vector</param> /// <returns>the dot product of this vector and v1</returns> public float Dot(Vector4f v1) { return (this.x * v1.x + this.y * v1.y + this.z * v1.z + this.w * v1.w); }
/// <summary> /// Returns the (4-space) angle in radians between this vector and /// the vector parameter; the return value is constrained to the /// range [0,PI]. /// </summary> /// <remarks> /// Returns the (4-space) angle in radians between this vector and /// the vector parameter; the return value is constrained to the /// range [0,PI]. /// </remarks> /// <param name="v1">the other vector</param> /// <returns>the angle in radians in the range [0,PI]</returns> public float Angle(Vector4f v1) { double vDot = this.Dot(v1) / (this.Length() * v1.Length()); if (vDot < -1.0) { vDot = -1.0; } if (vDot > 1.0) { vDot = 1.0; } return ((float)(Math.Acos(vDot))); }
/// <summary> /// Copies the matrix values in the specified column into the vector /// parameter. /// </summary> /// <remarks> /// Copies the matrix values in the specified column into the vector /// parameter. /// </remarks> /// <param name="column">the matrix column</param> /// <param name="v">the vector into which the matrix row values will be copied</param> public void GetColumn(int column, Vector4f v) { if (column == 0) { v.x = m00; v.y = m10; v.z = m20; v.w = m30; } else { if (column == 1) { v.x = m01; v.y = m11; v.z = m21; v.w = m31; } else { if (column == 2) { v.x = m02; v.y = m12; v.z = m22; v.w = m32; } else { if (column == 3) { v.x = m03; v.y = m13; v.z = m23; v.w = m33; } else { throw new IndexOutOfRangeException("Matrix4f getColumn"); } } } } }
/// <summary>Sets the specified row of this matrix4f to the Vector provided.</summary> /// <remarks>Sets the specified row of this matrix4f to the Vector provided.</remarks> /// <param name="row">the row number to be modified (zero indexed)</param> /// <param name="v">the replacement row</param> public void SetRow(int row, Vector4f v) { switch (row) { case 0: { this.m00 = v.x; this.m01 = v.y; this.m02 = v.z; this.m03 = v.w; break; } case 1: { this.m10 = v.x; this.m11 = v.y; this.m12 = v.z; this.m13 = v.w; break; } case 2: { this.m20 = v.x; this.m21 = v.y; this.m22 = v.z; this.m23 = v.w; break; } case 3: { this.m30 = v.x; this.m31 = v.y; this.m32 = v.z; this.m33 = v.w; break; } default: { throw new IndexOutOfRangeException("Matrix4f setRow"); } } }
/// <summary>Copies the matrix values in the specified row into the vector parameter. /// </summary> /// <remarks>Copies the matrix values in the specified row into the vector parameter. /// </remarks> /// <param name="row">the matrix row</param> /// <param name="v">the vector into which the matrix row values will be copied</param> public void GetRow(int row, Vector4f v) { if (row == 0) { v.x = m00; v.y = m01; v.z = m02; v.w = m03; } else { if (row == 1) { v.x = m10; v.y = m11; v.z = m12; v.w = m13; } else { if (row == 2) { v.x = m20; v.y = m21; v.z = m22; v.w = m23; } else { if (row == 3) { v.x = m30; v.y = m31; v.z = m32; v.w = m33; } else { throw new IndexOutOfRangeException("Matrix4f getRow"); } } } } }