List <LineParams> GenerateLineParams() { var lines = new List <LineParams>(); var equalizerWidth = numberOfLines * baseWidth + (numberOfLines - 1) * baseGap; var lengthInflections = RandomHelper.Points(0, numberOfLines, lengthInflectionCount); lengthInflections.Add(int.MaxValue); var nextLenInflection = lengthInflections[0]; lengthInflections.RemoveAt(0); var speedInflections = RandomHelper.Points(0, numberOfLines, speedInflectionCount); speedInflections.Add(int.MaxValue); var nextSpeedInflection = speedInflections[0]; speedInflections.RemoveAt(0); var currXPos = (CameraHelper.Width - equalizerWidth) * Random.value - CameraHelper.HalfWidth; var currLenDir = 1; var currLen = baseLength; var currSpeedDir = 1; var currSpeed = baseSpeed; for (int i = 0; i < numberOfLines; i++) { var line = new LineParams(); line.length = currLen; line.width = baseWidth; line.x = currXPos; line.y = (CameraHelper.Height + baseLength * 2) / -2f; line.velocity = Vector2.up * currSpeed; // for now, same speed lines.Add(line); // next currXPos += baseWidth + baseGap; currLen += currLenDir * lengthIncrement; currSpeed += speedIncrement * currSpeedDir; if (nextLenInflection <= i) { // reverse dir currLenDir *= -1; nextLenInflection = lengthInflections[0]; lengthInflections.RemoveAt(0); } if (nextSpeedInflection <= i) { // reverse dir currSpeedDir *= -1; nextSpeedInflection = speedInflections[0]; speedInflections.RemoveAt(0); } } return(lines); }
public SetLineParams() { InitializeComponent(); this.TopMost = true; lineParam = new LineParams(); //calculateparams(); }
void FireLine(LineParams lineP) { var p = CreatePlane(Quaternion.identity); p.localScale = lineP.scale; p.level = level; p.velocity = lineP.velocity; p.position = lineP.position; p.color = color; }
private void button3_Click(object sender, EventArgs e) { foreach (var listBoxItem in listBox_groupPath.Items) { String namepath = listBoxItem.ToString(); MessageBox.Show("" + namepath); LineParams templineparams = findLineParam(namepath); if (templineparams != null) { MessageBox.Show("line"); pathObjectList.Add(new PathObject() { flag_lineparam = true, lineParams = templineparams, curveParams = null }); } CurveParams tempcurveparams = findCurveParam(namepath); if (tempcurveparams != null) { MessageBox.Show("curve"); pathObjectList.Add(new PathObject() { flag_lineparam = false, curveParams = tempcurveparams, lineParams = null }); } } if (pathObjectList.Count > 0) { System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog(); if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (StreamWriter sw = File.CreateText(System.IO.Path.GetFullPath(saveFileDialog.FileName))) { sw.WriteLine("// X, Y, Z, W"); for (int i = 0; i < pathObjectList.Count; i++) { String path = ""; CreateRobotPathPlan createpath = new CreateRobotPathPlan(); if (pathObjectList[i].flag_lineparam) { createpath.linePathPlan(pathObjectList[i].lineParams); path += createpath.TextLine(); } else { createpath.CurvePathPlan(pathObjectList[i].curveParams); path += createpath.TextCurveLine(); } sw.Write(path); } } } } }
public void Test_FitTest() { var line = LineParams.FitLine(new List <PosXYZ>() { new PosXYZ(1d, 1d, 1.1d), new PosXYZ(2d, 2d, 2.2d), new PosXYZ(3d, 3d, 3.3d), new PosXYZ(44d, 44d, 44.4d), }); Console.WriteLine($"{line.Direction},{line.Origin}"); }
void CulcParams() { double[] x = DataArray[Keys["t"]].array; double[] y = DataArray[Keys["T"]].array; LineParams param = MNK(x, y); Betta = param.Betta; T0 = param.T0; dT = param.dT; Tstart = param.Tstart; Tend = param.Tend; }
private LineParams findLineParam(String Name) { LineParams lineparam = null; for (int i = 0; i < lineList.Count; i++) { if (lineList[i].Nameobj.Equals(Name)) { lineparam = lineList[i]; break; } } return(lineparam); }
List <LineParams> GenerateLineParams() { var lines = new List <LineParams>(); var equalizerWidth = numberOfLines * baseWidth + (numberOfLines - 1) * baseGap + largeGap * p_gap * 1.5f * numberOfLines; var currXPos = -0.5f * (CameraHelper.Width) - equalizerWidth; var yPos = (CameraHelper.Height - baseLength * 2) * Random.value - CameraHelper.HalfWidth; var currLenDir = 1; var currLen = baseLength; var currVelocityDir = 1; var currVelocity = baseVelocity; for (int i = 0; i < numberOfLines; i++) { var line = new LineParams(); line.length = currLen; line.width = baseWidth; line.x = currXPos; line.y = yPos; line.velocity = currVelocity; // for now, same velocity lines.Add(line); // next currXPos += baseWidth + baseGap; currLen += currLenDir * lengthIncrement; currVelocity += velocityIncrement * currVelocityDir; if (Random.value < p_lengthInflection) { currLenDir *= -1; } if (Random.value < p_velocityInflection) { currVelocityDir *= -1; } if (Random.value < p_gap) { currXPos += largeGap; } } return(lines); }
public void TestMethod_LineTest() { var line = LineParams.FitLine(new List <PosXYZ>() { new PosXYZ(0, 0, 1), new PosXYZ(0, 0, 2), new PosXYZ(0, 0, 3), }); Console.WriteLine($"FitLine:{line.Origin} {line.Direction}"); var dist = line.Distance(new PosXYZ(1, 1, 0)); Console.WriteLine($"Dist:{dist:F2}"); }
private void btn_openlistpath_Click(object sender, EventArgs e) { if (openpath()) { JObject results = JObject.Parse(contents); foreach (var result in results["Line"]) { string _Name = (string)result["name"]; listBox_singlepath.Items.Add(_Name); dynamic startPoint = result["startPoint"]; System.Windows.Point sp = new System.Windows.Point((double)startPoint.X, (double)startPoint.Y); dynamic endPoint = result["endPoint"]; System.Windows.Point ep = new System.Windows.Point((double)endPoint.X, (double)endPoint.Y); double _startdir = (double)result["startdir"]; double _enddir = (double)result["enddir"]; double _unitstep = (double)result["unitStep"]; LineParams lineparam = new LineParams() { Nameobj = _Name, startpoint = sp, endpoint = ep, startdir = _startdir, enddir = _enddir, unitstep = _unitstep }; lineList.Add(lineparam); } foreach (var result in results["Curve"]) { string Name = (string)result["name"]; listBox_singlepath.Items.Add(Name); dynamic startPoint = result["startPoint"]; System.Windows.Point sp = new System.Windows.Point((double)startPoint.X, (double)startPoint.Y); dynamic middlePoint = result["middlePoint"]; System.Windows.Point mp = new System.Windows.Point((double)middlePoint.X, (double)middlePoint.Y); dynamic endPoint = result["endPoint"]; System.Windows.Point ep = new System.Windows.Point((double)endPoint.X, (double)endPoint.Y); double _startdir = (double)result["startdir"]; double _enddir = (double)result["enddir"]; double R = (double)result["radius"]; double dv = (double)result["dv"]; double dw = (double)result["dw"]; CurveParams curveparam = new CurveParams() { Nameobj = Name, startpoint = sp, middlepoint = mp, endpoint = ep, startdir = _startdir, enddir = _enddir, R = R, dw = dw, dv = dv }; curveList.Add(curveparam); } } }
public LineParams Search(IReadOnlyList <Dot> dots) { LineParams Sum = default; var countPairs = 0; for (var i = 0; i < dots.Count; i++) { Dot left = dots[i]; for (int j = i + 1; j < dots.Count; j++) { Dot right = dots[j]; Sum += new LineParams( left.Y - right.Y, right.X - left.X, left.X * right.Y - right.X * left.Y); countPairs++; } } return(Sum / countPairs); }
public LineParams Search(IReadOnlyList <Dot> dots) { double minSum = int.MaxValue; int middleX = dots.Sum(d => d.X) / dots.Count; int middleY = dots.Sum(d => d.Y) / dots.Count; var middleDot = new Dot(middleX, middleY); LineParams besLineParams = default; for (double a = 0; a <= Math.PI; a += Math.PI / 1000) { var line = new LineParams(middleDot, a); double sum = dots.Sum(dot => line.GetDistance(dot)) / dots.Count; if (minSum > sum) { minSum = sum; besLineParams = line; } } return(besLineParams); }
public LineParams Search(IReadOnlyList <Dot> dots) { var e = 0.1; var minLine = new LineParams(0, 0, 0); double min = int.MaxValue; Parallel.For(-255, 255, c => { for (double a = -1; a < 1; a += e) { for (double b = -1; b < 1; b += e) { var line = new LineParams(a, b, c); double sum = 0; foreach (Dot dot in dots) { sum += line.GetDistance(dot); if (sum > min) { break; } } if (sum >= min) { continue; } minLine = new LineParams(a, b, c); min = sum; } } }); return(minLine); }
public AVGModel(Model InpModel, double startT, double endT, int[] DataIndex) { Keys.Add("T", 0); Keys.Add("TG", 1); Keys.Add("DTA", 2); Keys.Add("DTG", 3); for (int i = 0; i < InpModel.Count; i++) { int Dim = 4; AS SignalForSpeed = new AS(); SignalForSpeed.S = new Signal[Dim]; List <SimpleSignal> SpeedSignal = InpModel[i]; int[] StartInd = new int[SpeedSignal.Count]; int[] EndInd = new int[SpeedSignal.Count]; for (int j = 0; j < SpeedSignal.Count; j++) { StartInd[j] = TempToIndex(startT, SpeedSignal[j]); EndInd[j] = TempToIndex(endT, SpeedSignal[j]); } double dtemp = (endT - startT) / (EndInd[0] - StartInd[0]); double[] x = ConcateArray(SpeedSignal, StartInd, EndInd, "t"); double[] y = ConcateArray(SpeedSignal, StartInd, EndInd, "T"); LineParams param = MNK(x, y); SignalForSpeed.Betta = param.Betta; SignalForSpeed.T0 = param.T0; int N = (int)((endT - startT) / dtemp); SignalForSpeed.S[0] = new Signal(SpeedSignal[0].GetSignal("T")); List <Functions> Mass = new List <Functions>(); for (int j = 0; j < SpeedSignal.Count; j++) { Mass.Add(new Functions(new List <double>(SpeedSignal[j].GetSignal("T")), new List <double>(SpeedSignal[j].GetSignal("Mass")))); } AVGFunctions AVGMass = new AVGFunctions(Mass, 0); // x возьмем по первым данным, это можно исправить позже как решим SignalForSpeed.S[1] = AVGMass.Get(); //;new Signal(SpeedSignal[0].GetSignal("Mass")) if (DataIndex[DataIndex.Length - 1] != -1) { List <Functions> DSC = new List <Functions>(); for (int j = 0; j < SpeedSignal.Count; j++) { DSC.Add(new Functions(new List <double>(SpeedSignal[j].GetSignal("T")), new List <double>(SpeedSignal[j].GetSignal("DSC")))); } AVGFunctions AVGDSC = new AVGFunctions(DSC, 0); // x возьмем по первым данным, это можно исправить позже как решим SignalForSpeed.S[2] = AVGDSC.Get(); //new Signal(SpeedSignal[0].GetSignal("DSC")); } SignalForSpeed.S[3] = new Signal(new double[SpeedSignal[0].GetSignal("T").Length]); Signals.Add(SignalForSpeed); } bGrid = new List <double>(); for (int i = 0; i < Signals.Count; i++) { bGrid.Add(Signals[i].Betta); } bool f = true; while (f) { f = false; for (int i = 0; i < Signals.Count - 1; i++) { if (Signals[i].Betta > Signals[i + 1].Betta) { AS tmp = Signals[i]; Signals[i] = Signals[i + 1]; Signals[i + 1] = tmp; f = true; } } } DTG(); }
public bool IsSameLine(LineParams other) { return other.rise * this.run == other.run * this.rise && this.IsCollinear(other.aPoint); }
List <LineParams> GenerateLineParams() { var lines = new List <LineParams>(); var equalizerWidth = numberOfLines * baseWidth + (numberOfLines - 1) * baseGap; var lengthInflections = RandomHelper.Points(0, numberOfLines, lengthInflectionCount); lengthInflections.Add(int.MaxValue); var nextLenInflection = lengthInflections[0]; lengthInflections.RemoveAt(0); var velocityInflections = RandomHelper.Points(0, numberOfLines, velocityInflectionCount); velocityInflections.Add(int.MaxValue); var nextVelocityInflection = velocityInflections[0]; velocityInflections.RemoveAt(0); var gapInflections = RandomHelper.Points(0, numberOfLines, numberOfLargeGaps); gapInflections.Add(int.MaxValue); var nextGapInflection = gapInflections[0]; gapInflections.RemoveAt(0); var currXPos = -0.5f * (CameraHelper.Width + equalizerWidth); var yPos = (CameraHelper.Height - baseLength * 2) * Random.value - CameraHelper.HalfWidth; var currLenDir = 1; var currLen = baseLength; var currVelocityDir = 1; var currVelocity = baseVelocity; for (int i = 0; i < numberOfLines; i++) { var line = new LineParams(); line.length = currLen; line.width = baseWidth; line.x = currXPos; line.y = yPos; line.velocity = currVelocity; // for now, same velocity lines.Add(line); // next currXPos += baseWidth + baseGap; currLen += currLenDir * lengthIncrement; currVelocity += velocityIncrement * currVelocityDir; if (nextLenInflection <= i) { // reverse dir currLenDir *= -1; nextLenInflection = lengthInflections[0]; lengthInflections.RemoveAt(0); } if (nextVelocityInflection <= i) { // reverse dir currVelocityDir *= -1; nextVelocityInflection = velocityInflections[0]; velocityInflections.RemoveAt(0); } if (nextGapInflection <= i) { // reverse dir currXPos += largeGap; nextGapInflection = gapInflections[0]; gapInflections.RemoveAt(0); } } return(lines); }