namespace Day24; public record Line(Vec Position, Vec Velocity) { public Intersection IntersectionWith(Line other) { var a = (Position.Y - other.Position.Y) / (double)other.Velocity.Y; var b = (other.Position.X - Position.X) * ((double)Velocity.Y / (Velocity.X * other.Velocity.Y)); var c = (other.Velocity.X * Velocity.Y) / (double)(Velocity.X * other.Velocity.Y); var t2 = (a + b) / (1 - c); var t1 = ((other.Position.X - Position.X) + t2 * other.Velocity.X) / (double)Velocity.X; var v2 = other.Velocity.Multiply(t2); return new Intersection(t1, t2, other.Position.X + v2.X, other.Position.Y + v2.Y); } }