Fast and Arbitrary Beam Pattern Design for RIS-Assisted Terahertz Wireless Communication