/// <summary> /// 曲線 位置ベクトル /// </summary> /// <param name="t">パラメータ</param> /// <param name="dimension">(true, false) = (normal, 一階微分)</param> /// <returns></returns> public Vector3 PosiLine(float t, bool dimension) { Bernstein bt = new Bernstein(); if (dimension) { bt.Init(t); } else { bt.dInit(t); } Matrix4 cr_t = new Matrix4(); Matrix4 cp = new Matrix4(); Matrix4 tmp = new Matrix4(); Vector3 Pt = new Vector3(); for (int i = 0; i < 4; i++) { cr_t[0, i] = bt.b[i]; } // x for (int i = 0; i < 4; i++) { cp[i, 0] = ctrlpline[i].X; } tmp = cr_t * cp; Pt.X = tmp[0, 0]; // y for (int i = 0; i < 4; i++) { cp[i, 0] = ctrlpline[i].Y; } tmp = cr_t * cp; Pt.Y = tmp[0, 0]; // z for (int i = 0; i < 4; i++) { cp[i, 0] = ctrlpline[i].Z; } tmp = cr_t * cp; Pt.Z = tmp[0, 0]; return(Pt); }
/// <summary> /// 曲面 位置ベクトル /// </summary> /// <param name="u">U方向のパラメータ</param> /// <param name="v">V方向のパラメータ</param> /// <param name="mode">モード(0, 1, 2) = (null, u, v)</param> /// <returns></returns> public Vector3 PosiCurve(float u, float v, int mode) { Bernstein bu = new Bernstein(); Bernstein bv = new Bernstein(); if (mode == 1) { bu.dInit(u); bv.Init(v); } else if (mode == 2) { bu.Init(u); bv.dInit(v); } else { bu.Init(u); bv.Init(v); } Matrix4 cr_u = new Matrix4(); Matrix4 cr_v = new Matrix4(); Matrix4 cp = new Matrix4(); Matrix4 tmp = new Matrix4(); Vector3 Pt = new Vector3(); for (int i = 0; i < 4; i++) { cr_u[0, i] = bu.b[i]; cr_v[i, 0] = bv.b[i]; } // x for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cp[i, j] = ctrlpcurve[i][j].X; } } tmp = cr_u * cp; tmp = tmp * cr_v; Pt.X = tmp[0, 0]; // y for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cp[i, j] = ctrlpcurve[i][j].Y; } } tmp = cr_u * cp; tmp = tmp * cr_v; Pt.Y = tmp[0, 0]; // z for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cp[i, j] = ctrlpcurve[i][j].Z; } } tmp = cr_u * cp; tmp = tmp * cr_v; Pt.Z = tmp[0, 0]; return(Pt); }