Nick Kyrgios will meet Roger Federer in the third round of the U.S. Open. (Photo by Julian Finney/Getty Images)

NEW YORK — Roger Federer and Nick Kyrgios finished their second-round matches mere hours apart on courts that sit just across a food court from one another at Billie Jean King National Tennis Center, but they might as well have been playing in different worlds.

Federer advanced past volatile Frenchman Benoit Paire, 7-5, 6-4, 6-4, in Arthur Ashe Stadium, simply turning his back or casting his gaze to the ground whenever his opponent slammed his racket into the court in frustration. The match was ugly and staccato because of Paire’s tantrums, but Federer, as always, kept his composure.

Over on sunny Court 17, the mercurial Kyrgios also played true to form. He appeared to have withered in the heat in the first set of his 4-6, 7-6 (8-6), 6-3, 6-0 victory over Pierre-Hugues Herbert. He swore at himself. He swore at the crowd when they booed him yet barely mustered a reaction when one spectator yelled “Nick, you suck!” Then, after a controversial second-set visit with the chair umpire, he flipped a switch and took control.

Federer and Kyrgios were the two extremes on display Thursday at the U.S. Open, which operated under an extreme heat advisory for the players for the third day in a row.

On Saturday, tennis’s two poles will meet.

Kyrgios, 23, and 20-time Grand Slam champion Federer, 37. will clash for the fourth time in their careers but for the first time in a major tournament. The match pits one player who is a magnet for controversy against the one player most skilled at repelling it.

Kyrgios again found himself at the center of a storm Thursday.

The talented, enigmatic Aussie had just double-faulted away the first set and was trailing, 3-0, after a lackadaisical effort to start the second set when, during the changeover, chair umpire Mohamed Lahyani left his perch to have a chat with the No. 30 seed.

Kyrgios told the umpire he wasn’t feeling well and Lahyani responded, “I want to help you; let me help you,” in what many spectators, including several ESPN analysts, called an unfair pep talk. Kyrgios asked Lahyani to call the trainer and received salt packets on the next changeover.

The Australian won 19 of the next 25 games, a turnaround that prompted criticism that Layhani had reached beyond the scope of officiating and into improper on-court coaching.

“I didn’t see what happened,” Herbert said after the match. “I just saw that Nick from that point started to playing really, focused, 100 percent. Then I saw what happened after the match. … After this, for sure, when I saw how it went, you never know what would have happened if Mohamed didn’t go down of the chair and started talking to him.

“The only thing he can tell him is, yeah, pay attention, because if you continue like this, I’m going to give you a warning, something like this. They can tell him from the chair. He doesn’t need to go down. He doesn’t need to say the words he said on the video. I think this was not his job.”

Kyrgios laughed at the notion that Lahyani’s intervention helped him win.

“Not at all,” said Kyrgios, who mostly sat and stared straight ahead when Lahyani was pleading with him. “We all know I had that moment in Shanghai where the referee said the same thing, ‘It’s not good for the integrity of the sport, doesn’t have a good look’ … I’m not sure it was encouragement. He said he liked me. I’m not sure that’s encouragement.”

The U.S. Open released a statement that recapped the incident but did not detail any repercussions for Lahyani.

Federer, for his part, said he was sure the incident would not happen again. He agreed that it is beyond the role of an umpire to leave his or her chair and talk to a player about anything other than a medical situation.

“I get what he was trying to do, [Lahyani] behaves the way he behaves. … He was there for too long,” Federer said in a news conference after his match. “It’s a conversation. Conversations can change your mind-set. That’s why it won’t happen again.”

Try as Federer might to keep drama at bay, he and Kyrgios are bound to put on a show Saturday. Kyrgios has a history of flourishing on the biggest stages, when he unfurls his most dangerous serves, his forte, and pulls out his craftiest shot-making.

Kyrgios owns a strong record against the tour’s top players: He is 2-3 against Rafael Nadal and 2-0 vs. Novak Djokovic. Each of his and Federer’s three matches have been decided in a third-set tiebreaker, with the Swiss man owning the series 2-1. Kyrgios hasn’t beat him since their first meeting back in 2015.

“I’m going to put a lot of expectation on myself to play well,” Kyrgios said. “I’m not going to go out there and roll over and be happy to be out there. I do believe I can win. … We’ve never played best of five before. For sure, to win three sets off Federer, you have to play some pretty consistent tennis. But he’s never played me best of five, either.”

Federer has looked fresh as he’s rolled through these past two rounds while Kyrgios has battled — with himself, mainly — through two four-setters. Federer is vying for his sixth U.S. Open title, his first in a decade, while Kyrgios is looking to make it past the third round for the first time.

Win or lose, you can bet Federer will keep his cool. Kyrgios, well, that might be another story.

Read more:

Let’s talk about Serena Williams’s new look at the U.S. Open

Venus and Serena Williams are set to meet in the third round

U.S. Open accused of double standard after warning Alize Cornet for briefly taking off her shirt

Reviews are in — and the news Louis Armstrong Stadium is a hit