CARLA
 
载入中...
搜索中...
未找到
Deformation.h
浏览该文件的文档.
1// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <memory> // 引入内存管理的头文件
10#include <vector> // 引入动态数组的头文件
11
12#include <carla/geom/Mesh.h> // 引入Mesh类的定义
13#include <carla/road/Road.h> // 引入Road类的定义
14#include <carla/road/LaneSection.h> // 引入LaneSection类的定义
15#include <carla/road/Lane.h> // 引入Lane类的定义
16#include <carla/rpc/OpendriveGenerationParameters.h> // 引入Opendrive生成参数的定义
17
18namespace carla { // 定义carla命名空间
19namespace geom { // 定义geom命名空间
20namespace deformation { // 定义deformation命名空间
21
22 // 内联函数,用于计算给定坐标在变形中的z轴位置
23 inline float GetZPosInDeformation(float posx, float posy) {
24 // 振幅
25 const float A1 = 0.6f; // 第一振幅
26 const float A2 = 1.1f; // 第二振幅
27 // 相位
28 const float F1 = 1000.0; // 第一相位
29 const float F2 = -1500.0; // 第二相位
30 // 修改因子
31 const float Kx1 = 0.035f; // x方向的修改因子1
32 const float Kx2 = 0.02f; // x方向的修改因子2
33
34 const float Ky1 = -0.08f; // y方向的修改因子1
35 const float Ky2 = 0.05f; // y方向的修改因子2
36
37 // 计算并返回变形后的z轴位置
38 return A1 * sin((Kx1 * posx + Ky1 * posy + F1)) +
39 A2 * sin((Kx2 * posx + Ky2 * posy + F2));
40 }
41
42 // 内联函数,用于计算给定坐标的隆起变形
43 inline float GetBumpDeformation(float posx, float posy) {
44 const float A3 = 0.10f; // 隆起的振幅
45 float bumpsoffset = 0; // 隆起偏移量,初始化为0
46
47 float constraintX = 17.0f; // x方向的约束
48 float constraintY = 12.0f; // y方向的约束
49
50 // 计算与约束相关的隆起坐标
51 float BumpX = std::ceil(posx / constraintX); // 向上取整计算隆起x坐标
52 float BumpY = std::floor(posy / constraintY); // 向下取整计算隆起y坐标
53
54 // 将隆起坐标乘以约束,得到实际隆起坐标
55 BumpX *= constraintX;
56 BumpY *= constraintY;
57
58 // 计算到隆起中心的距离
59 float DistanceToBumpOrigin = sqrt(pow(BumpX - posx, 2) + pow(BumpY - posy, 2));
60 float MaxDistance = 2.0; // 最大距离限制
61
62 // 如果距离小于等于最大距离,则计算隆起偏移量
63 if (DistanceToBumpOrigin <= MaxDistance) {
64 bumpsoffset = sin(DistanceToBumpOrigin); // 使用距离计算隆起偏移量
65 }
66
67 // 返回最终的隆起变形值
68 return A3 * bumpsoffset;
69 }
70
71} // namespace deformation
72} // namespace geom
73} // namespace carla
float GetBumpDeformation(float posx, float posy)
Definition Deformation.h:43
float GetZPosInDeformation(float posx, float posy)
Definition Deformation.h:23
CARLA模拟器的主命名空间。
Definition Carla.cpp:139