public _Vector() { _Vector3D p1 = new _Vector3D(0, 0, 0); _Vector3D p2 = new _Vector3D(1, 1, 1); Init(p1, p2); }
// Quay quanh truc p0p1 public override void Rotate(float Angle, _Vector3D p0, _Vector3D p1) { _Vector3D v = p1 - p0; Translate(-p0.x, -p0.y, -p0.z); Rotate(Angle, v); Translate(p0.x, p0.y, p0.z); }
public static _Vector3D operator -(_Vector3D p1, _Vector3D p2) { _Vector3D result = new _Vector3D(); result.x = p1.x - p2.x; result.y = p1.y - p2.y; result.z = p1.z - p2.z; return(result); }
private void Init(_Vector3D p1, _Vector3D p2) { mBegin = p1; mEnd = p2; ChangeMatrix(); pObj = Glu.gluNewQuadric(); Glu.gluQuadricDrawStyle(pObj, Glu.GLU_FILL); Glu.gluQuadricNormals(pObj, Glu.GLU_SMOOTH); Glu.gluQuadricOrientation(pObj, Glu.GLU_OUTSIDE); Glu.gluQuadricTexture(pObj, Glu.GLU_FALSE); }
// Quay quanh truc bat ky public void Rotate(float angle, _Vector3D p0, _Vector3D p1) { _Vector3D v = p1 - p0; _Affine tran1 = new _Affine(); _Affine rot = new _Affine(); _Affine tran2 = new _Affine(); tran1.Translate(-p0.x, -p0.y, -p0.z); rot.Rotate(angle, v); tran2.Translate(p0.x, p0.y, p0.z); _Affine temp = tran1 + rot + tran2; _Math3D.CopyMatrix(mMatrix, temp.mMatrix); }
// Tinh chieu dai cua vector // (source code: SuperBible4) public static float GetDistance(_Vector3D u, _Vector3D v) { float x = u.x - v.x; x = x * x; float y = u.y - v.y; y = y * y; float z = u.z - v.z; z = z * z; return((float)Math.Sqrt(x + y + z)); }
public override void Translate(float Ox, float Oy, float Oz) { float[] p1 = new float[3] { pBegin.x, pBegin.y, pBegin.z }; float[] p2 = new float[3] { pEnd.x, pEnd.y, pEnd.z }; _Affine tran = new _Affine(); tran.Translate(Ox, Oy, Oz); p1 = tran.ConvertPoint(p1); p2 = tran.ConvertPoint(p2); mBegin = new _Vector3D(p1); mEnd = new _Vector3D(p2); ChangeMatrix(); }
public override void Rotate(float Angle, float Ox, float Oy, float Oz) { float[] p1 = new float[3] { pBegin.x, pBegin.y, pBegin.z }; float[] p2 = new float[3] { pEnd.x, pEnd.y, pEnd.z }; _Affine rot = new _Affine(); rot.Rotate(Angle, Ox, Oy, Oz); p1 = rot.ConvertPoint(p1); p2 = rot.ConvertPoint(p2); mBegin = new _Vector3D(p1); mEnd = new _Vector3D(p2); ChangeMatrix(); }
// Ham tinh lai ma tran cua vector khi co su thay doi vi tri 2 dau cua vector private void ChangeMatrix() { // Di chuyen hinh den vi tri tuong ung Center[0] = 0; Center[1] = 0; Center[2] = 0; _Affine Iden = new _Affine(); Iden.Identity(); Matrix = (float[])Iden; _Vector3D v1 = new _Vector3D(0, 0, 1); _Vector3D v2 = pEnd - pBegin; _Vector3D Normal = _Math3D.FindNormalVector(v1, v2); double rad = _Math3D.GetAngleBetweenVectors(v1, v2); if (Normal.x != 0 || Normal.y != 0 || Normal.z != 0) { base.Rotate((float)(rad * 180 / Math.PI), Normal.x, Normal.y, Normal.z); } base.Translate(pBegin.x - Center[0], pBegin.y - Center[1], pBegin.z - Center[2]); }
public static _Vector3D CrossProduct(_Vector3D u, _Vector3D v) { float[] result = new float[3]; CrossProduct(result, (float[])u, (float[])v); return(result); }
public override void Rotate(float Angle, _Vector3D v) { Rotate(Angle, v.x, v.y, v.z); }
public static float GetAngleBetweenVectors(_Vector3D u, _Vector3D v) { return(GetAngleBetweenVectors((float[])u, (float[])v)); }
public _Vector(_Vector3D p) { _Vector3D p1 = new _Vector3D(0, 0, 0); Init(p1, p); }
public static _Vector3D NormalizeVector(_Vector3D u) { float[] temp = (float[])u; NormalizeVector(temp); return(temp); }
public static float GetVectorLength(_Vector3D u) { return(GetVectorLength((float[])u)); }
public static _Vector3D ScaleVector3(_Vector3D v, float scale) { float[] temp = (float[])v; ScaleVector3(temp, scale); return(temp); }
public static _Vector3D FindNormalVector(_Vector3D v1, _Vector3D v2) { return(FindNormalVector((float[])v1, (float[])v2)); }
public void Axisymmetric(_Vector3D v) { Axisymmetric(new float[3] { 0, 0, 0 }, (float[])v); }
public void Rotate(float angle, _Vector3D v) { Rotate(angle, v.x, v.y, v.z); }
public _Vector(_Vector3D p1, _Vector3D p2) { Init(p1, p2); }
public _Vector3D(_Vector3D p) { Init(p.x, p.y, p.z); }