Apollo 10.0
自动驾驶开放平台
angle.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
20
21namespace apollo {
22namespace common {
23namespace math {
24
25float sin(Angle16 a) {
26 int16_t idx = a.raw();
27
28 if (idx < -Angle16::RAW_PI_2) {
29 idx = static_cast<int16_t>(idx + Angle16::RAW_PI);
30 return -SIN_TABLE[idx % SIN_TABLE_SIZE];
31 }
32 if (idx < 0) {
33 return -SIN_TABLE[(-idx) % SIN_TABLE_SIZE];
34 }
35 if (idx < Angle16::RAW_PI_2) {
36 return SIN_TABLE[idx % SIN_TABLE_SIZE];
37 }
38 idx = static_cast<int16_t>(Angle16::RAW_PI - idx);
39 return SIN_TABLE[idx % SIN_TABLE_SIZE];
40}
41
42float cos(Angle16 a) {
43 Angle16 b(static_cast<int16_t>(Angle16::RAW_PI_2 - a.raw()));
44 return sin(b);
45}
46
47float tan(Angle16 a) { return sin(a) / cos(a); }
48
49float sin(Angle8 a) {
50 Angle16 b(static_cast<int16_t>(a.raw() << 8));
51 return sin(b);
52}
53
54float cos(Angle8 a) {
55 Angle16 b(static_cast<int16_t>(a.raw() << 8));
56 return cos(b);
57}
58
59float tan(Angle8 a) {
60 Angle16 b(static_cast<int16_t>(a.raw() << 8));
61 return tan(b);
62}
63
64} // namespace math
65} // namespace common
66} // namespace apollo
Defines the templated Angle class.
The Angle class uses an integer to represent an angle, and supports commonly-used operations such as ...
Definition angle.h:58
T raw() const
Getter of value_.
Definition angle.h:112
static constexpr T RAW_PI
Internal representation of pi
Definition angle.h:90
static constexpr T RAW_PI_2
Internal representation of pi/2
Definition angle.h:93
float cos(Angle16 a)
Definition angle.cc:42
const float SIN_TABLE[16385]
Definition sin_table.cc:25
float sin(Angle16 a)
Definition angle.cc:25
float tan(Angle16 a)
Definition angle.cc:47
class register implement
Definition arena_queue.h:37
Exports the SIN_TABLE, used by the Angle class.
#define SIN_TABLE_SIZE
Used by Angle class to speed-up computation of trigonometric functions.
Definition sin_table.h:33