Cone beam computed tomography (CBCT) has become a vital tool in interventional radiology. Usually, a circular source-detector trajectory is used to acquire a three-dimensional (3D) image. Kinematic constraints due to the patient size or additional medical equipment often cause collisions with the imager while performing a full circular rotation. In a previous study, we developed a framework to design collision-free, patient-specific trajectories for the cases in which circular CBCT is not feasible. Our proposed trajectories included enough information to appropriately reconstruct a particular volume of interest (VOI), but the constraints had to be defined before the intervention. As most collisions are unpredictable, performing an on-the-fly trajectory optimization is desirable. In this study, we propose a search strategy that explores a set of trajectories that cover the whole collision-free area and subsequently performs a search locally in the areas with the highest image quality. Selecting the best trajectories is performed using simulations on a prior diagnostic CT volume which serves as a digital phantom for simulations. In our simulations, the Feature SIMilarity Index (FSIM) is used as the objective function to evaluate the imaging quality provided by different trajectories. We investigated the performance of our methods using three different anatomical targets inside the Alderson-Rando phantom. We used FSIM and Universal Quality Image (UQI) to evaluate the final reconstruction results. Our experiments showed that our proposed trajectories could achieve a comparable image quality in the VOI compared to the standard C-arm circular CBCT. We achieved a relative deviation less than 10% for both FSIM and UQI metrics between the reconstructed images from the optimized trajectories and the standard C-arm CBCT for all three targets. The whole trajectory optimization took approximately three to four minutes.