Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
a4b83e2c
Commit
a4b83e2c
authored
Feb 19, 2017
by
Craig Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better calculation of angles
parent
452383b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
UBGeometryUtils.cpp
src/frameworks/UBGeometryUtils.cpp
+13
-4
UBGeometryUtils.h
src/frameworks/UBGeometryUtils.h
+1
-1
No files found.
src/frameworks/UBGeometryUtils.cpp
View file @
a4b83e2c
...
...
@@ -255,8 +255,6 @@ QPolygonF UBGeometryUtils::arcToPolygon(const QLineF& startRadius, qreal spanAng
*/
QPolygonF
UBGeometryUtils
::
curveToPolygon
(
const
QList
<
QPointF
>&
points
,
qreal
startWidth
,
qreal
endWidth
)
{
typedef
QPair
<
QPointF
,
QPointF
>
pointPair
;
int
n_points
=
points
.
size
();
if
(
n_points
<
2
)
...
...
@@ -431,7 +429,18 @@ void UBGeometryUtils::crashPointList(QVector<QPointF> &points)
/**
* @brief Return the angle between three points
*/
qreal
UBGeometryUtils
::
angle
(
const
QPointF
&
a
,
const
QPointF
&
b
,
const
QPointF
&
c
)
qreal
UBGeometryUtils
::
angle
(
const
QPointF
&
p1
,
const
QPointF
&
p2
,
const
QPointF
&
p3
)
{
return
(
QLineF
(
a
,
b
).
angle
()
-
QLineF
(
b
,
c
).
angle
());
// Angle between three points, using the law of cosines:
// The angle at B equals arccos((a^2-b^2-c^2)/(2*a*c)), where a, b and c are the sides of the triangle
// opposite A, B and C, respectively
qreal
a
,
b
,
c
,
beta
;
a
=
qSqrt
(
qPow
(
p2
.
x
()
-
p3
.
x
(),
2
)
+
qPow
(
p2
.
y
()
-
p3
.
y
(),
2
));
b
=
qSqrt
(
qPow
(
p1
.
x
()
-
p3
.
x
(),
2
)
+
qPow
(
p1
.
y
()
-
p3
.
y
(),
2
));
c
=
qSqrt
(
qPow
(
p1
.
x
()
-
p2
.
x
(),
2
)
+
qPow
(
p1
.
y
()
-
p2
.
y
(),
2
));
beta
=
qAcos
((
a
*
a
-
b
*
b
-
c
*
c
)
/
(
2
*
a
*
c
));
return
2
*
3.14159
*
beta
;
}
src/frameworks/UBGeometryUtils.h
View file @
a4b83e2c
...
...
@@ -55,7 +55,7 @@ class UBGeometryUtils
static
void
crashPointList
(
QVector
<
QPointF
>
&
points
);
static
qreal
angle
(
const
QPointF
&
a
,
const
QPointF
&
b
,
const
QPointF
&
c
);
static
qreal
angle
(
const
QPointF
&
p1
,
const
QPointF
&
p2
,
const
QPointF
&
p3
);
const
static
int
centimeterGraduationHeight
;
const
static
int
halfCentimeterGraduationHeight
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment