Irving Schachter, an AP Physics teacher at Brooklyn Tech for nearly 40 years, was hit by a cyclist who swerved and entered the running lane, knocking him out and putting him into a coma from which he never awoke.Facebook

Before he was struck Aug. 3, Irving Schachter, 75, planned to run 18 miles — as training for the athletic Upper East Side man’s second marathon.

His wife Hindy Schachter, a 69-year-old professor, ran 5 miles with him before going home that day.

Irving Schachter with his wife Hindy SchachterHandout

“We were talking about how he was going to train me to run faster,” she said of their last moments together. “And he was going to do that with hill repeats, intervals and lots of interesting things. We had a great conversation.”

Irving Schachter (center) with his former studentsFacebook

But a 17-year-old cyclist swerved to avoid a pedicab driver and went into the running lane, knocking Schachter unconscious.

He went into a coma and died two days later at New York Presbyterian Hospital of a head injury.

“I didn’t think of him as elderly,” Hindy told The Post on Thursday. “He was a fantastic amateur cyclist. We liked to go to the theater, we hiked.”

The longtime sweethearts met in the summer of 1967 and were married within a few months.

Their daughter, Amanda, is an architect who founded a firm with her husband.

“May his humility, generosity of spirit and good humor, as well as his acuity of mind and his quietly fierce competitive heart in matters of concentration and strategy find its way into us,” she wrote in a recent online post.

Irving Schachter was known as the “Shack” to his students, and taught AP Physics for decades at Brooklyn Technical High School in Fort Greene.

“He was a brilliant guy,” said former student Eugene Cheleshkin, 35, a software developer in Bay Ridge who added that Schachter inspired him to go into technology.

“He could take a complicated subject and make it fun. One of the best teachers ever. He was No. one.”

Schachter also loved chess and cycling, and friends from the New York Cycling Club shared memories of cycling with him this week on a message board.

“That day, probably just one of hundreds of rides Irv led and of thousands he did, has stayed with me,” wrote safe streets advocate Charles Komanoff of a ride he took with him. “I’ve thought of him often. I’m so sorry that he’s been taken away.”