物理模型建模demo
Posted aarond
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了物理模型建模demo相关的知识,希望对你有一定的参考价值。
第一次做物理建模这事,还挺有意思,由于只是demo,没有深入研究下去,所以这个目标也就比较浅显,只是:检测旋转到某1角度不要发生碰撞,不带重力
from shapely.geometry import Polygon from shapely import affinity import matplotlib.pyplot as plt def make_car(leftX, leftY, width, height): car_lines = Polygon([(leftX, leftY), (leftX+width, leftY), (leftX+width, leftY+height), (leftX, leftY+height), (leftX, leftY)]) return car_lines def showCar(car): # x, y = car.xy x, y=car.exterior.xy plt.plot(x, y) def showCars(cars): for car in cars: showCar(car) car_width=4.7 car_height=2.5 car1 = make_car(1, 1, car_width, car_height) car2 = make_car(6, 1, car_width, car_height) car3 = make_car(11, 1, car_width, car_height) car4 = make_car(16, 1, car_width, car_height) car5 = make_car(1, 6, car_width, car_height) car6 = make_car(6, 6, car_width, car_height) car7 = make_car(11, 6, car_width, car_height) car8 = make_car(16, 6, car_width, car_height) plt.axis(‘equal‘) plt.ion() cars = [car1, car2, car3, car4, car5, car6, car7, car8] showCars(cars) plt.pause(1) for i in range(1, 30): plt.cla() rotated_car3 = affinity.rotate(car3, i) showCars([car1, car2, rotated_car3, car4, car5, car6, car7, car8]) #计算是否碰撞 print(‘=======================‘, i, ‘====================‘) cars = [car1, car2, car4, car5, car6, car7, car8] conflict=False for car in cars: if rotated_car3.intersects(car): conflict=True break if conflict: print(‘撞到了,当前旋转角度:‘, i) break plt.pause(0.1) plt.ioff() plt.show()
代码比较简单,用到的有几何库:shapely https://shapely.readthedocs.io/en/stable/manual.html
以上是关于物理模型建模demo的主要内容,如果未能解决你的问题,请参考以下文章
论文阅读|《基于时序数据库的产品数字孪生模型海量动态数据建模方法》
shader编程-三维场景下SDF建模,对模型进行扭曲弯曲裁剪掏空操作(WebGL-Shader开发基础12)