当前位置: 首页>>代码示例>>Python>>正文


Python Track.contains方法代码示例

本文整理汇总了Python中track.Track.contains方法的典型用法代码示例。如果您正苦于以下问题:Python Track.contains方法的具体用法?Python Track.contains怎么用?Python Track.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在track.Track的用法示例。


在下文中一共展示了Track.contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Simulator

# 需要导入模块: from track import Track [as 别名]
# 或者: from track.Track import contains [as 别名]
class Simulator(object):

    def __init__(self):
        self.step_period = None
        self.car   = Car(410., 750.)
        self.track = Track()

    def test_car_position(self):
        return self.track.contains(self.car.corners, self.car.edges)

    def get_sensor_values(self):
        result = dict()
        sensor_data = self.car.get_sensor_data()
        for name,data in sensor_data.items():
            dst = self.compute_distance(data)
            print(name, dst)
            result[name] = data['s'].distance_to_voltage(dst)
        return result

    def compute_distance(self, data):
        if data['uv'][0] != 0:
            a = data['uv'][1]/data['uv'][0]
            c = data['pos'][1]-a*data['pos'][0]

        distance = None
        for a2,c2,xmin,xmax in self.track.lines:
            if data['uv'][0] == 0:
                x = data['pos'][0]
            else:
                if a == a2:
                    # print("parallel")
                    continue
                x = (c2-c)/(a-a2)
            if round(x,0) > round(xmax,0) or round(x,0) < round(xmin,0):
                # print("out of bounds {:>10.2f} {:>10.2f} {:>10.2f}".format(xmin, x, xmax))
                continue

            if data['uv'][0] == 0:
                dst = (a2*x+c2-data['pos'][1])/data['uv'][1]
            else:
                dst = (x-data['pos'][0])/data['uv'][0]
            if dst < 0:
                # print("Found point {} is not in the direction of the unit vector {}".format(x, dst))
                continue
            else:
                # print("Found suitable point {} with distance {}".format(x, dst))
                if distance is None or dst < distance:
                    distance = dst
        return distance
开发者ID:marjakm,项目名称:common,代码行数:51,代码来源:api.py


注:本文中的track.Track.contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。