本文整理汇总了C#中TimeStep类的典型用法代码示例。如果您正苦于以下问题:C# TimeStep类的具体用法?C# TimeStep怎么用?C# TimeStep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimeStep类属于命名空间,在下文中一共展示了TimeStep类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TimeValueList
/// <summary>
/// Creates a new regular-spaced list and sets all values to initialValue
/// </summary>
/// <param name="period"></param>
/// <param name="step"></param>
/// <param name="initialValue"></param>
/// <returns></returns>
public TimeValueList(TimeInterval period, TimeStep step, double initialValue)
{
_timeStepFactor = (step == TimeStep.Hour) ? 24 : 1;
_start = period.Start.ToOADate();
switch(TimeStep)
{
case TimeStep.Hour:
_data = new double[(int) period.Length.TotalHours];
break;
case TimeStep.Day:
_data = new double[(int) period.Length.TotalDays];
break;
default:
throw new ArgumentException("'step' parameter must be 'Hour' or 'Day'");
}
if (initialValue != 0.0)
{
// initialize array values...
for (int i = 0; i < _data.Length; ++i)
{
_data[i] = initialValue;
}
}
}
示例2: GetMissingValuesHydro
public static HydroTimeSeries GetMissingValuesHydro(ITimeSeries ts, DateTime start, DateTime end, TimeStep step)
{
HydroTimeSeries missingTs = new HydroTimeSeries(start, end);
List<int> breakIx = GetDataBreaks(ts);
//TODO missing points before series start
foreach (int begIndex in breakIx)
{
if (begIndex < ts.Count - 1)
{
DateTime begDate = DateTime.FromOADate(ts[begIndex].X);
DateTime endDate = DateTime.FromOADate(ts[begIndex + 1].X);
if (step == TimeStep.Day)
{
int nd = (int)endDate.Subtract(begDate).TotalDays;
for (int i = 0; i < nd; i++)
{
DateTime newTime = begDate.AddDays(i);
missingTs.AddUnknownValue(newTime);
}
}
else
{
int nh = (int)endDate.Subtract(begDate).TotalHours;
for (int i = 0; i < nh; i++)
{
DateTime newTime = begDate.AddHours(i);
missingTs.AddUnknownValue(newTime);
}
}
}
}
return missingTs;
}
示例3: FillDataGaps
/// <summary>
/// Fills the data gaps inside the time-series by setting them to 'no data' vals
/// </summary>
/// <param name="ts"></param>
public static ITimeSeries FillDataGaps(ITimeSeries ts, TimeStep step)
{
ITimeSeries myTs = MakeRegularTimeSeries(ts.Start, ts.End, step);
if (step == TimeStep.Day)
{
double tStart = myTs[0].X;
for (int i = 0; i < ts.Count - 1; i++)
{
double index = (ts[i].X - tStart);
int ix = (int)index;
myTs[ix].Y = ts[i].Y;
}
}
else
{
double tStart = myTs[0].X * 24;
for (int i = 0; i < ts.Count - 1; i++)
{
double index = (ts[i].X * 24 - tStart);
int ix = (int)index;
myTs[ix].Y = ts[i].Y;
}
}
return myTs;
}
示例4: ServiceRate
public ServiceRate(string serviceName,TimeStep timeStep,DateTime stamp,int rate)
{
this.ServiceName = serviceName;
this.RateTimeStep = timeStep;
this.TimeStamp = stamp;
this.Rate = rate;
}
示例5: Step
public override void Step(TimeStep step)
{
if (_bodyList == null) return;
if (useWorldGravity)
{
gravity = _world.Gravity;
}
for (ControllerEdge i = _bodyList; i != null; i = i.nextBody)
{
Body body = i.body;
if (body.IsSleeping())
{
//Buoyancy force is just a function of position,
//so unlike most forces, it is safe to ignore sleeping bodes
continue;
}
Vec2 areac = new Vec2(0, 0);
Vec2 massc = new Vec2(0, 0);
float area = 0;
float mass = 0;
for (Shape shape = body.GetShapeList(); shape != null; shape = shape.GetNext())
{
Vec2 sc;
float sarea = shape.ComputeSubmergedArea(normal, offset, body.GetXForm(), out sc);
area += sarea;
areac.X += sarea * sc.X;
areac.Y += sarea * sc.Y;
float shapeDensity = 0;
if (useDensity)
{
//TODO: Expose density publicly
shapeDensity = shape.Density;
}
else
{
shapeDensity = 1;
}
mass += sarea * shapeDensity;
massc.X += sarea * sc.X * shapeDensity;
massc.Y += sarea * sc.Y * shapeDensity;
}
areac.X /= area;
areac.Y /= area;
massc.X /= mass;
massc.Y /= mass;
if (area < Box2DX.Common.Settings.FLT_EPSILON)
continue;
//Buoyancy
Vec2 buoyancyForce = -density * area * gravity;
body.ApplyForce(buoyancyForce, massc);
//Linear drag
Vec2 dragForce = body.GetLinearVelocityFromWorldPoint(areac) - velocity;
dragForce *= -linearDrag * area;
body.ApplyForce(dragForce, areac);
//Angular drag
//TODO: Something that makes more physical sense?
body.ApplyTorque(-body.GetInertia() / body.GetMass() * area * body.GetAngularVelocity() * angularDrag);
}
}
示例6: InitVelocityConstraints
internal override void InitVelocityConstraints(ref TimeStep step)
{
_jointError = BodyA.Sweep.A - TargetAngle;
_bias = -BiasFactor * step.inv_dt * _jointError;
_massFactor = (1 - Softness) / (BodyA.InvI);
}
示例7: Step
public override void Step(TimeStep step)
{
for (ControllerEdge i = _bodyList; i != null; i = i.nextBody)
{
Body body = i.body;
if (body.IsSleeping())
continue;
body.SetLinearVelocity(body.GetLinearVelocity() + step.Dt * A);
}
}
示例8: Step
public override void Step(TimeStep step)
{
//B2_NOT_USED(step);
for (ControllerEdge i = _bodyList; i != null; i = i.nextBody)
{
Body body = i.body;
if (body.IsSleeping())
continue;
body.ApplyForce(F, body.GetWorldCenter());
}
}
示例9: ReadBinaryFile
public static void ReadBinaryFile(string fileName, DateTime startTime, DateTime endTime, TimeStep timeStep,
bool includeNA, IObservationList observations)
{
if (timeStep == TimeStep.Day)
{
ReadBinaryFileDaily(fileName, startTime, endTime, includeNA, observations);
}
else
{
ReadBinaryFileHourly(fileName, startTime, endTime, includeNA, observations);
}
}
示例10: RunLogic
protected internal override void RunLogic(TimeStep step)
{
foreach (Body e in this.Bodies)
{
if (e.IgnoresGravity ||
e.IgnoresPhysicsLogics)
{
continue;
}
Vector2D.Add(ref e.State.Acceleration.Linear, ref gravity, out e.State.Acceleration.Linear);
}
}
示例11: Detect
public override void Detect(TimeStep step)
{
for (int index1 = 0; index1 < this.Bodies.Count; index1++)
{
Body body1 = this.Bodies[index1];
for (int index2 = index1 + 1; index2 < this.Bodies.Count; index2++)
{
Body body2 = this.Bodies[index2];
if ((body1.Mass.MassInv != 0 || body2.Mass.MassInv != 0) &&
Body.CanCollide(body1, body2) &&
body1.Rectangle.Intersects(body2.Rectangle))
{
OnCollision(step, body1, body2);
}
}
}
}
示例12: RunLogic
protected internal override void RunLogic(TimeStep step)
{
foreach (Body e in this.Bodies)
{
if (e.IgnoresGravity ||
e.IgnoresPhysicsLogics)
{
continue;
}
Vector2D vect;
Vector2D.Subtract(ref location, ref e.State.Position.Linear, out vect);
Vector2D.Normalize(ref vect, out vect);
Vector2D.Multiply(ref vect, ref gravity, out vect);
Vector2D.Add(ref e.State.Acceleration.Linear, ref vect, out e.State.Acceleration.Linear);
}
}
示例13: Step
public override void Step(TimeStep step)
{
float timestep = step.Dt;
if (timestep <= Settings.FLT_EPSILON)
return;
if (timestep > MaxTimestep && MaxTimestep > 0)
timestep = MaxTimestep;
for (ControllerEdge i = _bodyList; i != null; i = i.nextBody)
{
Body body = i.body;
if (body.IsSleeping())
continue;
Vec2 damping = body.GetWorldVector(Math.Mul(T, body.GetLocalVector(body.GetLinearVelocity())));
body.SetLinearVelocity(body.GetLinearVelocity() + timestep*damping);
}
}
示例14: RunLogic
protected internal override void RunLogic(TimeStep step)
{
foreach (Body e in Bodies)
{
if (e == body ||
e.IgnoresGravity ||
e.IgnoresPhysicsLogics)
{
continue;
}
Scalar magnitude;
Vector2D gravity;
Vector2D.Subtract(ref body.State.Position.Linear, ref e.State.Position.Linear, out gravity);
Vector2D.Normalize(ref gravity, out magnitude, out gravity);
magnitude = (body.Mass.AccelerationDueToGravity /
(magnitude * magnitude * metersPerDistanceUnit * metersPerDistanceUnit));
Vector2D.Multiply(ref gravity, ref magnitude, out gravity);
Vector2D.Add(ref e.State.Acceleration.Linear, ref gravity, out e.State.Acceleration.Linear);
}
}
示例15: LoadObservationsDischarge
/// <summary>
/// Retrieves a time series of discharge observations from the database
/// (only measured, non-zero values are retrieved)
/// </summary>
/// <param name="stationId"></param>
/// <param name="variableId"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="scaleFactor"></param>
/// <param name="observations"></param>
public static void LoadObservationsDischarge(int stationId, int variableId, DateTime start, DateTime end,
TimeStep step, IObservationList observations)
{
//observations.Clear();
SqlCommand cmd = DataUtils.CreateCommand();
cmd.CommandText = "plaveninycz.new_query_observations";
cmd.CommandType = CommandType.StoredProcedure;
SetCmdParameters(cmd, stationId, variableId, start, end, step);
SqlDataReader rdr;
double val;
DateTime t;
try
{
cmd.Connection.Open();
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (rdr.Read())
{
if (!rdr.IsDBNull(1))
{
t = Convert.ToDateTime(rdr[0]);
val = Convert.ToDouble(rdr[1]);
//val = Math.Pow(2.0, (val / 1000.0));
if (val > 0)
{
observations.AddObservation(t, val);
}
else
{
observations.AddUnknownValue(t);
}
}
}
rdr.Close();
}
finally
{
cmd.Connection.Close();
}
}