mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-04 12:36:46 +03:00
make quadratic dist work for DES. seems to work! but need to adjust ALL
intervals...
This commit is contained in:
parent
e1259587cb
commit
46a8414f21
@ -288,7 +288,7 @@ impl Car {
|
||||
self.intervals.split_off(idx1 + 1);
|
||||
|
||||
// Option 1: Might be too sharp.
|
||||
if true {
|
||||
if false {
|
||||
{
|
||||
let mut our_adjusted_last = self.intervals.pop().unwrap();
|
||||
|
||||
@ -326,8 +326,16 @@ impl Car {
|
||||
let them = &leader.intervals[idx2];
|
||||
let mut our_adjusted_last = self.intervals.pop().unwrap();
|
||||
our_adjusted_last.end_speed = them.end_speed;
|
||||
our_adjusted_last.end_time = them.end_time;
|
||||
our_adjusted_last.end_dist = them.end_dist - dist_behind;
|
||||
our_adjusted_last.end_time = them.end_time;
|
||||
/*our_adjusted_last.end_time = find_end_time_for_interval(
|
||||
our_adjusted_last.start_dist,
|
||||
our_adjusted_last.end_dist,
|
||||
our_adjusted_last.start_speed,
|
||||
our_adjusted_last.end_speed,
|
||||
our_adjusted_last.start_time,
|
||||
);*/
|
||||
println!("adjusted interval: {}", our_adjusted_last);
|
||||
self.intervals.push(our_adjusted_last);
|
||||
}
|
||||
|
||||
@ -344,3 +352,24 @@ impl Car {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_end_time_for_interval(
|
||||
initial_dist: Distance,
|
||||
final_dist: Distance,
|
||||
initial_speed: Speed,
|
||||
final_speed: Speed,
|
||||
initial_time: Duration,
|
||||
) -> Duration {
|
||||
let g = final_dist.inner_meters();
|
||||
let d = initial_dist.inner_meters();
|
||||
let v = initial_speed.inner_meters_per_second();
|
||||
let f = final_speed.inner_meters_per_second();
|
||||
let s = initial_time.inner_seconds();
|
||||
|
||||
let numer = -2.0 * d + s * (f + v) + 2.0 * g;
|
||||
let denom = f + v;
|
||||
let t = Duration::seconds(numer / denom);
|
||||
|
||||
assert!(t > initial_time);
|
||||
t
|
||||
}
|
||||
|
@ -57,17 +57,12 @@ impl Interval {
|
||||
}
|
||||
|
||||
pub fn dist(&self, t: Duration) -> Distance {
|
||||
if true {
|
||||
// Linearly interpolate
|
||||
self.start_dist + self.percent(t) * (self.end_dist - self.start_dist)
|
||||
} else {
|
||||
let relative_t = (t - self.start_time).inner_seconds();
|
||||
let relative_t = (t - self.start_time).inner_seconds();
|
||||
|
||||
let d = self.start_dist.inner_meters()
|
||||
+ self.start_speed.inner_meters_per_second() * relative_t
|
||||
+ 0.5 * self.raw_accel() * relative_t.powi(2);
|
||||
Distance::meters(d)
|
||||
}
|
||||
let d = self.start_dist.inner_meters()
|
||||
+ self.start_speed.inner_meters_per_second() * relative_t
|
||||
+ 0.5 * self.raw_accel() * relative_t.powi(2);
|
||||
Distance::meters(d)
|
||||
}
|
||||
|
||||
pub fn speed(&self, t: Duration) -> Speed {
|
||||
@ -107,25 +102,7 @@ impl Interval {
|
||||
}
|
||||
|
||||
// Set the two distance equations equal and solve for time. Long to type out here...
|
||||
let t = if true {
|
||||
let x1 = self.start_dist.inner_meters();
|
||||
let x2 = self.end_dist.inner_meters();
|
||||
let a1 = self.start_time.inner_seconds();
|
||||
let a2 = self.end_time.inner_seconds();
|
||||
|
||||
let y1 = leader.start_dist.inner_meters();
|
||||
let y2 = leader.end_dist.inner_meters();
|
||||
let b1 = leader.start_time.inner_seconds();
|
||||
let b2 = leader.end_time.inner_seconds();
|
||||
|
||||
let numer =
|
||||
a1 * (b2 * (y1 - x2) + b1 * (x2 - y2)) + a2 * (b2 * (x1 - y1) + b1 * (y2 - x1));
|
||||
let denom = (a1 - a2) * (y1 - y2) + b2 * (x1 - x2) + b1 * (x2 - x1);
|
||||
if denom == 0.0 {
|
||||
return None;
|
||||
}
|
||||
Duration::seconds(numer / denom)
|
||||
} else {
|
||||
let t = {
|
||||
let x_1 = self.start_dist.inner_meters();
|
||||
let v_1 = self.start_speed.inner_meters_per_second();
|
||||
let t_1 = self.start_time.inner_seconds();
|
||||
|
Loading…
Reference in New Issue
Block a user