Skip to content

Commit 8afebae

Browse files
committed
acute angle between two straight lines
1 parent 3afebc0 commit 8afebae

File tree

5 files changed

+74
-30
lines changed

5 files changed

+74
-30
lines changed

src/geometry/acute.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3+
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef ACUTE_H
20+
#define ACUTE_H
21+
22+
23+
#include <Eigen/Core>
24+
25+
#include <cassert>
26+
#include <cfloat>
27+
#include <cmath>
28+
#include <cstdlib>
29+
30+
31+
namespace Geometry {
32+
33+
using Eigen::Vector2d;
34+
using Eigen::Vector3d;
35+
36+
37+
//! acute angle between two straight lines in radians
38+
static inline double acute( const Vector3d l, const Vector3d m)
39+
{
40+
constexpr double pi = 3.141592653589793;
41+
constexpr double pi_2 = 3.141592653589793/2;
42+
43+
Vector2d lh = l.head(2);
44+
Vector2d mh = m.head(2);
45+
assert( lh.norm() > FLT_EPSILON );
46+
assert( mh.norm() > FLT_EPSILON );
47+
lh.normalize();
48+
mh.normalize();
49+
50+
assert( std::fabs(lh.dot(mh)) <= 1.0 ); // a'*b in [-1,+1]
51+
double alpha = std::acos( lh.dot(mh) ); // [0,pi]
52+
if ( alpha > pi_2) {
53+
alpha = pi -alpha;
54+
}
55+
assert( alpha >= 0.0 );
56+
assert( alpha <= pi_2 );
57+
58+
return alpha;
59+
}
60+
61+
} // namespace Geometry
62+
63+
#endif // ACUTE_H

src/greasepad.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ HEADERS += \
5151
conncomp.h \
5252
constraints.h \
5353
geometry/aabb.h \
54+
geometry/acute.h \
5455
geometry/conics.h \
5556
geometry/minrot.h \
5657
geometry/skew.h \

src/state.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "adjustment.h"
3636
#include "conncomp.h"
3737
#include "constraints.h"
38+
#include "geometry/acute.h"
3839
#include "global.h"
3940
#include "mainscene.h"
4041
#include "matfun.h"
@@ -892,15 +893,16 @@ bool impl::are_orthogonal( const Index a,
892893
bool impl::are_identical( const Index a,
893894
const Index b)
894895
{
895-
// pre-check with acute angle
896-
const double alpha = m_segm.at(a)->ul().acute( m_segm.at(b)->ul() );
897-
constexpr double rho = 180./3.14159;
896+
// (1) pre-check with acute angle
897+
const double alpha = Geometry::acute( m_segm.at(a)->ul().v(),
898+
m_segm.at(b)->ul().v() );
899+
constexpr double rho = 180./3.141592653589793; // = 180°/pi = 57.2958°
898900
constexpr double T_deg_pre_check = 20.0;
899-
if ( alpha*rho > T_deg_pre_check ) { // 180°/pi = 57.2958°
901+
if ( alpha*rho > T_deg_pre_check ) {
900902
return false;
901903
}
902904

903-
// statistical test
905+
// (2) statistical test
904906
return m_segm.at(a)->straightLineIsIdenticalTo( m_segm.at(b)->ul(),
905907
State::recogn_.quantile_chi2_2dof() );
906908
}

src/ustraightline.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -152,28 +152,6 @@ uPoint uStraightLine::project(const uPoint &ux) const
152152
}
153153

154154

155-
156-
double uStraightLine::acute(const uStraightLine &um) const
157-
{
158-
Eigen::Vector2d a = v().head(2);
159-
Eigen::Vector2d b = um.v().head(2);
160-
assert( a.norm() > FLT_EPSILON );
161-
assert( b.norm() > FLT_EPSILON );
162-
a.normalize();
163-
b.normalize();
164-
165-
assert( fabs(a.dot(b)) <= 1.0 ); // a'*b in [-1,+1]
166-
double alpha = acos( a.dot(b) ); // [0,pi]
167-
if ( alpha > M_PI_2) { // M_PI_2 = pi/2
168-
alpha = M_PI -alpha;
169-
}
170-
assert( alpha >= 0.0 );
171-
assert( alpha <= M_PI_2 );
172-
return alpha;
173-
}
174-
175-
176-
177155
//! Get Euclidean normalized version of this uncertain straight line
178156
uStraightLine uStraightLine::euclidean() const
179157
{

src/ustraightline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
3-
* Copyright (c) 2022-2025 Jochen Meidow, Fraunhofer IOSB
3+
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -54,8 +54,8 @@ class uStraightLine : public BasicEntity2D
5454
//! Signed distance between (0,0) and this straight line
5555
[[nodiscard]] double signedDistanceToOrigin() const { return v()(2)/v().head(2).norm(); }
5656

57+
//! Project point onto straight line
5758
[[nodiscard]] uPoint project( const uPoint & ux) const;
58-
[[nodiscard]] double acute( const uStraightLine & um ) const;
5959

6060
// unary relations ..................................................
6161
[[nodiscard]] bool isVertical( double T) const;

0 commit comments

Comments
 (0)