|
21 | 21 | using M4f = OpenTK.Matrix4;
|
22 | 22 | using M3d = OpenTK.Matrix3d;
|
23 | 23 | using PT = OpenTK.Graphics.OpenGL4.PrimitiveType;
|
| 24 | +using MathNet.Numerics.Distributions; |
| 25 | +using static System.Windows.Forms.DataFormats; |
24 | 26 | #endregion 定義
|
25 | 27 |
|
26 | 28 | namespace Crystallography.OpenGL;
|
@@ -693,7 +695,7 @@ public Lines(V3d[] vertices, float lineWidth, Material mat) : base(mat, DrawingM
|
693 | 695 | CircumscribedSphereRadius = vertices.Max(v => (v - center).Length);
|
694 | 696 | Vertices = vertices.Select(v => new Vertex(v.ToV3f(), mat.Argb)).ToArray();
|
695 | 697 | Indices = Enumerable.Range(0, vertices.Length).Select(i => (uint)i).ToArray();
|
696 |
| - Primitives = new[] { (PT.LineStrip, vertices.Length) }; |
| 698 | + Primitives = [(PT.LineStrip, vertices.Length)]; |
697 | 699 | }
|
698 | 700 | }
|
699 | 701 |
|
@@ -868,7 +870,7 @@ static V3d[][] decompose(V3d[] srcVertex, int ord)
|
868 | 870 | /// <param name="c">頂点c</param>
|
869 | 871 | /// <param name="mat"></param>
|
870 | 872 | /// <param name="mode"></param>
|
871 |
| -public class Triangle(V3d a, V3d b, V3d c, Material mat, DrawingMode mode) : Polygon(new V3d[] { a, b, c }, mat, mode) |
| 873 | +public class Triangle(V3d a, V3d b, V3d c, Material mat, DrawingMode mode) : Polygon([a, b, c], mat, mode) |
872 | 874 | {
|
873 | 875 | public Triangle(Vector3DBase a, Vector3DBase b, Vector3DBase c, Material mat, DrawingMode mode)
|
874 | 876 | : this(new V3d(a.X, a.Y, a.Z), new V3d(b.X, b.Y, b.Z), new V3d(c.X, c.Y, c.Z), mat, mode) { }
|
@@ -915,6 +917,82 @@ public Disk(V3d origin, V3d normal, double radius, float lineWidth, Material mat
|
915 | 917 | { LineWidth = lineWidth; }
|
916 | 918 | }
|
917 | 919 |
|
| 920 | +/// <summary> |
| 921 | +/// 穴あきディスク |
| 922 | +/// </summary> |
| 923 | +public class HoledDisk : GLObject |
| 924 | +{ |
| 925 | + public double RadiusInner, RadiusOuter; |
| 926 | + |
| 927 | + public V3d Origin, Normal; |
| 928 | + public HoledDisk(V3d origin, V3d normal, double radius1, double radius2, Material mat, DrawingMode mode, int slices = 60):base(mat,mode) |
| 929 | + { |
| 930 | + RadiusInner=Math.Min(radius1, radius2); |
| 931 | + RadiusOuter=Math.Max(radius1, radius2); |
| 932 | + Origin = origin; |
| 933 | + Normal = normal; |
| 934 | + |
| 935 | + CircumscribedSphereCenter = new V4d(origin, 1); |
| 936 | + CircumscribedSphereRadius = RadiusOuter; |
| 937 | + |
| 938 | + var sins = Enumerable.Range(0, slices).Select(i => Math.Sin((double)i / slices * 2 * Math.PI)).ToArray(); |
| 939 | + var coss = Enumerable.Range(0, slices).Select(i => Math.Cos((double)i / slices * 2 * Math.PI)).ToArray(); |
| 940 | + |
| 941 | + IgnoreNormalSides = true; |
| 942 | + |
| 943 | + M3d rotMat; |
| 944 | + if (normal == vZ) |
| 945 | + rotMat = M3d.Identity; |
| 946 | + else |
| 947 | + rotMat = M3d.CreateFromAxisAngle(V3d.Cross(normal, vZ), V3d.CalculateAngle(vZ, normal)); |
| 948 | + |
| 949 | + var vertices = new V3d[slices * 2]; |
| 950 | + |
| 951 | + for (int i = 0; i < slices; i++) |
| 952 | + { |
| 953 | + vertices[i] = new V3d(RadiusOuter * sins[i], RadiusOuter * coss[i], 0); |
| 954 | + vertices[i+slices] = new V3d(RadiusInner * sins[i], RadiusInner * coss[i], 0); |
| 955 | + } |
| 956 | + |
| 957 | + List<int> indicesTmp = []; |
| 958 | + for (int i = 0; i < slices; i++) |
| 959 | + { |
| 960 | + if (i < slices - 1) |
| 961 | + indicesTmp.AddRange([i, i + 1, i + slices + 1, i + slices]); |
| 962 | + else |
| 963 | + indicesTmp.AddRange([i, 0, slices + 1, i + slices]); |
| 964 | + } |
| 965 | + var types = new List<PT>(); |
| 966 | + var indices = new List<int[]>(); |
| 967 | + |
| 968 | + types.Add(PT.Quads); |
| 969 | + indices.Add([.. indicesTmp]); |
| 970 | + |
| 971 | + types.Add(PT.LineLoop); |
| 972 | + indices.Add([.. indicesTmp]); |
| 973 | + |
| 974 | + types.Add(PT.Points); |
| 975 | + indices.Add(Enumerable.Range(0, vertices.Length).ToArray()); |
| 976 | + |
| 977 | + Vertices = new Vertex[vertices.Length]; |
| 978 | + for (int i = 0; i < vertices.Length; i++) |
| 979 | + Vertices[i] = new Vertex((rotMat.Mult(vertices[i]) + origin).ToV3f(), normal.ToV3f(), mat.Argb); |
| 980 | + |
| 981 | + Indices = indices.SelectMany(i => i).Select(i => (uint)i).ToArray(); |
| 982 | + |
| 983 | + Primitives = types.Select((t, i) => (t, indices[i].Length)).ToArray(); |
| 984 | + |
| 985 | + |
| 986 | + } |
| 987 | + |
| 988 | + public HoledDisk(Vector3DBase origin, Vector3DBase normal, double radius1, double radius2, Material mat, DrawingMode mode, int slices = 60) |
| 989 | + : this(new V3d(origin.X, origin.Y, origin.Z), new V3d(normal.X, normal.Y, normal.Z), radius1, radius2, mat, mode, slices) { } |
| 990 | + |
| 991 | + public HoledDisk(V3d origin, V3d normal, double radius1, double radius2, float lineWidth, Material mat, DrawingMode mode, int slices = 60) |
| 992 | + : this(origin, normal, radius1, radius2, mat, mode, slices) |
| 993 | + { LineWidth = lineWidth; } |
| 994 | +} |
| 995 | + |
918 | 996 | #endregion
|
919 | 997 |
|
920 | 998 | #region 多面体、立方体
|
@@ -1235,7 +1313,8 @@ public Pipe(in V3d o, in V3d vec, in double r1, in double r2, Material mat, Draw
|
1235 | 1313 | /// <param name="vec">始点から終点へのベクトル</param>
|
1236 | 1314 | /// <param name="r1">始点側の半径</param>
|
1237 | 1315 | /// <param name="r2">終点側の半径</param>
|
1238 |
| - /// <param name="mat">素材</param> |
| 1316 | + /// <param name="mat1">素材</param> |
| 1317 | + /// <param name="mat2">素材 (指定しない場合はmat1と同じ, 指定した場合は半分がこれになる)</param> |
1239 | 1318 | /// <param name="mode">描画モード</param>
|
1240 | 1319 | /// <param name="sole">trueの場合は底面を描画する</param>
|
1241 | 1320 | /// <param name="slices">高さの分割数</param>
|
@@ -1321,9 +1400,9 @@ public Pipe(in V3d o, in V3d vec, in double r1, in double r2, Material mat1, Mat
|
1321 | 1400 | {
|
1322 | 1401 | current = h * stacks + t;
|
1323 | 1402 | if (t < stacks - 1)
|
1324 |
| - indiceSide.AddRange(new[] { current, current + stacks, current + 1 + stacks, current + 1 }); |
| 1403 | + indiceSide.AddRange([current, current + stacks, current + 1 + stacks, current + 1]); |
1325 | 1404 | else
|
1326 |
| - indiceSide.AddRange(new[] { current, current + stacks, current + 1, current + 1 - stacks }); |
| 1405 | + indiceSide.AddRange([current, current + stacks, current + 1, current + 1 - stacks]); |
1327 | 1406 | }
|
1328 | 1407 | var types = new List<PT>();
|
1329 | 1408 | var indices = new List<int[]>();
|
|
0 commit comments