Untitled
unknown
plain_text
a year ago
5.5 kB
3
Indexable
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Numerics; using MathNet.Numerics.Interpolation; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.Differentiation; using OpenCvSharp; using OpenCvSharp.Extensions; namespace Path_Planning_Dwarfboard_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); // Instantiate the PrepareCoordinates PrepareCoordinates = new PreparingCoordinates(); WheelDSpline(); } private PreparingCoordinates PrepareCoordinates; public string filePath = "D:\\data.txt"; private int Z; private int[] t_knot; struct ppType { public string form; public double[] breaks; public double[][] coefs; public int pieces; public int order; public int dim; }; struct Coordinates { public double[] x; public double[] y; }; //public double[] Dknot_xValues = { 439.5, 666.5, 893.5, 1120.5, 1288.5, 1453.5, 1603.5, 1732.5, 1840.5, 1927.5, 2032.5, 2170.5, 2332.5, 2503.5, 2680.5, 2851.5, 3088.5, 3526.5, 3928.5, 4207.5 }; //public double[] Dknot_yValues = { 500, 500, 500, 500, 500, 506, 566, 647, 764, 884, 989, 1061, 1100, 1121, 1121, 1124, 1121, 1127, 1127, 1130 }; //public List<double> Dknot_xValues; //public List<double> Dknot_yValues; public double[] Dknot_xValues; public double[] Dknot_yValues; public void WheelDSpline() { double W = 180; double L = 300; string impath = "TMK_plan.png"; int Z = 5; //Mat img = Cv2.ImRead(impath); bool manual = false; PrepareCoordinates.save(filePath); (Dknot_xValues, Dknot_yValues) = PrepareCoordinates.load(filePath); Console.WriteLine("Dknot_xValues: "); printArray(Dknot_xValues); Console.WriteLine(); Console.WriteLine("Dknot_yValues: ", Dknot_yValues); printArray(Dknot_yValues); Z = Dknot_xValues.Length; t_knot = new int[Z]; for (int i = 0; i < Z; i++) { t_knot[i] = i; } printArray(t_knot); } public static void printArray<T>(T[] array) { if (array == null || array.Length == 0) { Console.WriteLine("Array is empty or null."); return; } Console.WriteLine(); foreach (var item in array) { Console.Write(item + " "); } Console.WriteLine(); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Path_Planning_Dwarfboard_1 { public class PreparingCoordinates { public double[] Dknot_xValues = { 439.5, 666.5, 893.5, 1120.5, 1288.5, 1453.5, 1603.5, 1732.5, 1840.5, 1927.5, 2032.5, 2170.5, 2332.5, 2503.5, 2680.5, 2851.5, 3088.5, 3526.5, 3928.5, 4207.5 }; public double[] Dknot_yValues = { 500, 500, 500, 500, 500, 506, 566, 647, 764, 884, 989, 1061, 1100, 1121, 1121, 1124, 1121, 1127, 1127, 1130 }; //string filePath = "d_knot_20.txt"; public void save(string filePath) { using (StreamWriter writer = new StreamWriter(filePath)) { writer.WriteLine(string.Join(",", Dknot_xValues)); writer.WriteLine(string.Join(",", Dknot_yValues)); } Console.WriteLine("Data saved to: " + filePath); } /*public (List<double> xValues, List<double> yValues) load(string filePath) { List<double> xValues = new List<double>(); List<double> yValues = new List<double>(); using (StreamReader reader = new StreamReader(filePath)) { string xLine = reader.ReadLine(); string yLine = reader.ReadLine(); xValues = xLine.Split(',').Select(double.Parse).ToList(); yValues = yLine.Split(',').Select(double.Parse).ToList(); } Console.WriteLine("X-axis values: "); foreach (var x in xValues) { Console.WriteLine(x); } Console.WriteLine("Y-axis values: "); foreach (var y in yValues) { Console.WriteLine(y); } return (xValues, yValues); }*/ public (double[] xValues, double[] yValues) load(string filePath) { double[] xValues; double[] yValues; using (StreamReader reader = new StreamReader(filePath)) { string xLine = reader.ReadLine(); string yLine = reader.ReadLine(); xValues = xLine.Split(',').Select(double.Parse).ToArray(); yValues = yLine.Split(',').Select(double.Parse).ToArray(); } return (xValues, yValues); } } }
Editor is loading...
Leave a Comment