private void CreateSymmetryMesh(MyVector3 profilenormal_, double radius_) { int n = this.profile.Count; // base stroke point count int m = this.trajectory1.Count; // ref stroke point count // sweep the points, duplicate n times and offsetting List <double> vertices = new List <double>(); foreach (MyVector3 points in profile) { vertices.AddRange(points.ToArray()); } // set base stroke main axis MyVector3 dir = profilenormal_.Normalize(); MyVector3 basecenter3 = new MyVector3(); for (int i = 0; i < n; i++) { basecenter3 += this.profile[i]; } basecenter3 /= n; int closestidx = -1; //3d double dis = double.MaxValue; for (int i = 0; i < n; i++) { double d = (this.profile[i] - this.trajectory1.First()).Length(); if (d < dis) { closestidx = i; dis = d; } } double basescale = radius_; MyVector3 o3 = basecenter3; double tx = 0, ty = 0, tz = 0; double sn = 1; List <MyVector3> onerow = new List <MyVector3>(); onerow.AddRange(this.profile); for (int i = 0; i < m; i++) { Line3 normalline = new Line3(o3, dir); MyVector3 refp1 = normalline.ProjectToLine(this.trajectory1[i]); MyVector3 refp0 = normalline.ProjectToLine(onerow[closestidx]); MyVector3 tv = refp1 - refp0; tx += tv.x; ty += tv.y; tz += tv.z; o3 += tv; double d1 = (this.trajectory1[i] - refp1).Length(); sn = d1 / basescale; double[] new_points = new double[n * 3]; //one row onerow.Clear(); for (int j = 0, k = 0; j < n; ++j, k += 3) //move base point { new_points[k] = vertices[k] + tx; new_points[k + 1] = vertices[k + 1] + ty; new_points[k + 2] = vertices[k + 2] + tz; MyVector3 tp = new MyVector3(new_points, k); double oplength = (o3 - tp).Length(); oplength = oplength * sn; MyVector3 opdir = (tp - o3).Normalize(); double t = oplength; new_points[k] = opdir.x * t + o3.x; new_points[k + 1] = opdir.y * t + o3.y; new_points[k + 2] = opdir.z * t + o3.z; onerow.Add(new MyVector3(new_points, k)); } vertices.AddRange(new_points); } List <int> findices = new List <int>(); for (int i = 0; i < m; ++i) { for (int j = 0; j < n - 1; ++j) { int s = i * n + j, t = i * n + j + 1; int p = (i + 1) * n + j, q = (i + 1) * n + j + 1; // s-t-p, t-p-q findices.Add(s); findices.Add(p); findices.Add(t); findices.Add(t); findices.Add(p); findices.Add(q); } } this.objectmesh = new Mesh(vertices, findices); }