public SimulationModeItemManager(ContextMenuStrip contextMenuStrip, CarModelGraphicControl graphicControl) { model = new CarModel(new CarModelState(new PointD(ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X), ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)), new PointD(0, 1))); finish = new FinishModel(new PointD(ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X), ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)), 0); obstacles = new List <ObstacleModel>(); dragables = new List <IDragable>(); sampledCarState = model.state; dragables.Add(model); dragables.Add(finish); dragged = null; state = State.NONE; this.contextMenuStrip = contextMenuStrip; this.graphicControl = graphicControl; contextMenuStrip.Items[0].Click += new EventHandler(newObstacle); contextMenuStrip.Items[1].Click += new EventHandler(deleteObstacle); }
///发送数据 public void SendCommand(string command) { byte[] sendData = ComMath.Hex16StringToByteArry(command); if (ComDevice.IsOpen) { try { ComDevice.Write(sendData, 0, sendData.Length);//发送数据 } catch (Exception ex) { MessageBox.Show("发送失败:" + ex.Message); } } }
public static GridObstacleState FromObstacleState(ObstacleState obst, GridCarModelState state) { double d = ComMath.Normal(Math.Sqrt(obst.pp.position.X * obst.pp.position.X + obst.pp.position.Y * obst.pp.position.Y), GridCarModelState.MIN_DIST, GridCarModelState.MAX_DIST, 0, 1); double a = ComMath.Normal(state.TargetDist, GridCarModelState.MIN_DIST, GridCarModelState.MAX_DIST, 0, 1); double ang = Math.PI - (Math.Atan2(obst.pp.position.Y, obst.pp.position.X) + Math.PI) + state.TargetAngle - state.TargetFinishAngle; if (ang > Math.PI) { ang -= 2 * Math.PI; } if (ang < -Math.PI) { ang += 2 * Math.PI; } double AA = -2 * d * Math.Cos(ang); double BB = d * d; double obstdist = Math.Sqrt(a * a + BB + AA * a); double obstang = state.TargetAngle + Math.Sign(ang) * Math.Acos((a * a + obstdist * obstdist - d * d) / (2 * a * obstdist)); GridObstacleState gos = new GridObstacleState(obstdist, obstang, obst.radius); return(gos); }
public Bitmap Visualize(int width, int height, RectangleF rect, int xindex, int yindex, double[] otherargs, int outpindex, double minNeuronOutp, double maxNeuronOutp) { lock (this) { uint[] buf = new uint[width * height]; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { double[] inp = new double[otherargs.Length]; for (int i = 0; i < otherargs.Length; ++i) { inp[i] = otherargs[i]; } inp[xindex] = ComMath.Normal(x, 0, width - 1, rect.Left, rect.Right); inp[yindex] = ComMath.Normal(y, 0, height - 1, rect.Top, rect.Bottom); double[] outp = this.Output(inp); int blue = 0; int green = 0; int red = 0; blue = (int)ComMath.Normal(outp[outpindex], minNeuronOutp, maxNeuronOutp, 255, 0); //if (outp[outpindex] >= -1) //else { blue = 255; green = 255; } green = (int)ComMath.Normal(outp[outpindex], minNeuronOutp, maxNeuronOutp, 0, 255); //if (outp[outpindex] <= 1) //else { red = 255; green = 255; } if (blue > 255) { blue = 255; } if (blue < 0) { blue = 0; } if (red > 255) { red = 255; } if (red < 0) { red = 0; } if (green > 255) { green = 255; } if (green < 0) { green = 0; } buf[y * width + x] = 0xFF000000 + (uint)(red * 256 * 256 + green * 256 + blue); } } Bitmap bm = new Bitmap(width, height); BitmapData bmData = bm.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb); int len = bmData.Width * bmData.Height; unsafe { uint *cim = (uint *)bmData.Scan0.ToPointer();//direkt bitmap memoriaba rajzolunk, gyors for (int i = 0; i < len; ++i) { cim[i] = buf[i]; } } bm.UnlockBits(bmData); return(bm); } }