public CarSize(CarSize size) { width = new float(); height = new float(); width = size.width; height = size.height; }
/// <summary> /// 車や車線のサイズを取得する /// </summary> private void GetCarSize() { CarSize = new List <CarSize>(CarNum); float Ch = (float)(2.0 * PB.Width / Length); //全車共通 float a = (float)(Ch / 2); for (int i = 0; i < CarNum; i++) { CarSize CS = new CarSize(); CS.height = Ch; float w; if (CMB_ModelMode.Text == "CHPTモデル") { w = (float)((int)(v1.car[i].eigenvalue.length * 10 + 0.5) * 0.1); } else { w = (float)((int)(4.435 * 10 + 0.5) * 0.1); } CS.width = w * a; CarSize.Add(CS); } RoadTop = 10; RoadWidth = Ch + 2; RoadBottom = RoadTop + (int)(RoadWidth + 2.5); hundred_meter = PB.Width / 10; startY = RoadBottom + 7; endY = startY + 6; hundred_meter_X = hundred_meter + 10; fifty_meter_X = hundred_meter / 2 + 10; int topY = (int)(endY + 4.5); point0 = new Rectangle(2, topY, 21, 21); point50 = new Rectangle((int)(fifty_meter_X - 14 + 0.5), topY, 32, 21); point100 = new Rectangle((int)(hundred_meter_X - 19 + 0.5), topY, 43, 21); Velocity = new Rectangle(Width - 480, topY, 230, 21); ETime = new Rectangle(Width - 250, topY, 250, 21); }
/// <summary> /// 車と車線を描画する /// </summary> /// <param name="g">ref Graphics</param> private void DrawingCars(ref Graphics g) { Change_Unit unit = new Change_Unit(); Pen pen = new Pen(Color.Black, 2); g.DrawLine(pen, 0, RoadTop, PB.Width, RoadTop); int CY = RoadTop + 2; float R = (float)(PB.Width / Length); float velocity = 0; if (CHPT) { for (int i = 0; i < v1.car.Count; i++) { Brush brush = Brushes.Black; if (v1.driver[i].running.pedal.foot_position == FootPosition.brake_pedal || v1.car[i].running.velocity.current <= unit.km_h__to__m_s(0.3)) { brush = Brushes.Red; } CarSize size = CarSize[i]; int CX = (int)(R * v1.car[i].running.position.current - size.width + 0.5); g.FillRectangle(brush, CX, CY, size.width, size.height); if (CX < 0) { CX += PB.Width; g.FillRectangle(brush, CX, CY, PB.Width, size.height); } velocity += (float)v1.car[i].running.velocity.current; } } else { double RRR = Length / revised.LaneLength; for (int i = 0; i < revised.car.position.current.Count; i++) { Brush brush = Brushes.Black; if (revised.car.velocity[i] == 0 || revised.car.accelaration[i] < 0) { brush = Brushes.Red; } CarSize size = CarSize[i]; double next_p = pposition[i]; if (Animated) { next_p += revised.car.velocity[i] * time; } double position = RRR * next_p; pposition[i] = (float)next_p; int CX = (int)(R * position - size.width + 0.5); g.FillRectangle(brush, CX, CY, size.width, size.height); if (CX < 0) { CX += PB.Width; g.FillRectangle(brush, CX, CY, PB.Width, size.height); } velocity += (float)1.0 * revised.car.velocity[i] / 5 * 100; } } g.DrawLine(pen, 0, RoadBottom, PB.Width, RoadBottom); g.DrawLine(pen, 10, RoadBottom + 10, hundred_meter_X, RoadBottom + 10); g.DrawLine(pen, 10, startY, 10, endY); g.DrawLine(pen, fifty_meter_X, startY, fifty_meter_X, endY); g.DrawLine(pen, hundred_meter_X, startY, hundred_meter_X, endY); Font fnt = new Font("MS UI Gothic", 16, FontStyle.Bold); g.DrawString("0", fnt, Brushes.Black, point0); g.DrawString("50", fnt, Brushes.Black, point50); g.DrawString("100", fnt, Brushes.Black, point100); string S = "平均速度 : "; double km; if (CHPT) { km = unit.m_s__to__km_h(velocity / v1.car.Count); } else { km = 1.0 * velocity / revised.N; } S += string.Format("{0, 5}", string.Format("{0:f1}", 0.1 * (int)(km * 10 + 0.5))); S += "[km/h]"; g.DrawString(S, fnt, Brushes.Black, Velocity); S = " 経過時間 : "; double etime = time * z; S += string.Format("{0, 8}", string.Format("{0:f2}", 0.01 * (int)(etime * 100 + 0.5))); S += "[s]"; g.DrawString(S, fnt, Brushes.Black, ETime); fnt.Dispose(); pen.Dispose(); }