IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antonio Augusto Alves Junior
corsika
Commits
2b5ead11
Commit
2b5ead11
authored
6 years ago
by
Maximilian Reininghaus
Browse files
Options
Downloads
Patches
Plain Diff
enhanced geometry_example.cc
parent
ce8eeec5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Documentation/Examples/geometry_example.cc
+40
-21
40 additions, 21 deletions
Documentation/Examples/geometry_example.cc
with
40 additions
and
21 deletions
Documentation/Examples/geometry_example.cc
+
40
−
21
View file @
2b5ead11
/*
from within ngc/build/ directory:
g++ -O3 -I ../third_party/ -I<path to eigen> -I ../ -Wall -pedantic \
-std=c++14 ../Main/geometry_example.cc \
../Framework/Geometry/CoordinateSystem.cc -o geometry_example
*/
#include
<Geometry/Vector.h>
#include
<Geometry/Vector.h>
#include
<Geometry/Sphere.h>
#include
<Geometry/Sphere.h>
#include
<Geometry/Point.h>
#include
<Geometry/Point.h>
...
@@ -12,32 +5,58 @@
...
@@ -12,32 +5,58 @@
#include
<Units/PhysicalUnits.h>
#include
<Units/PhysicalUnits.h>
#include
<iostream>
#include
<iostream>
#include
<typeinfo>
#include
<cstdlib>
#include
<cstdlib>
using
namespace
phys
::
units
;
using
namespace
phys
::
units
;
using
namespace
phys
::
units
::
io
;
// support stream << unit
using
namespace
phys
::
units
::
literals
;
// support unit literals like 5_m;
int
main
()
int
main
()
{
{
using
namespace
phys
::
units
;
//~ // define the root coordinate system
using
namespace
phys
::
units
::
io
;
using
namespace
phys
::
units
::
literals
;
CoordinateSystem
root
;
CoordinateSystem
root
;
Point
const
p1
(
root
,
{
0
_m
,
0
_m
,
0
_m
});
// another CS defined by a translation relative to the root CS
CoordinateSystem
cs2
=
root
.
translate
({
0
_m
,
0
_m
,
1
_m
});
CoordinateSystem
cs2
=
root
.
translate
({
0
_m
,
0
_m
,
1
_m
});
Point
const
p2
(
cs2
,
{
0
_m
,
0
_m
,
0
_m
});
Vector
<
length_d
>
const
diff
=
p2
-
p1
;
// rotations are possible, too; parameters are axis vector and angle
auto
const
norm
=
diff
.
squaredNorm
();
CoordinateSystem
cs3
=
root
.
rotate
({
1
_m
,
0
_m
,
0
_m
},
90
*
degree_angle
);
// now let's define some geometrical objects:
Point
const
p1
(
root
,
{
0
_m
,
0
_m
,
0
_m
});
// the origin of the root CS
Point
const
p2
(
cs2
,
{
0
_m
,
0
_m
,
0
_m
});
// the origin of cs2
Vector
<
length_d
>
const
diff
=
p2
-
p1
;
// the distance between the points, basically the translation vector given above
auto
const
norm
=
diff
.
squaredNorm
();
// squared length with the right dimension
std
::
cout
<<
"p2-p1 components: "
<<
diff
.
getComponents
()
<<
std
::
endl
;
// print the components of the vector as given in the different CS
std
::
cout
<<
"p2-p1 components in root: "
<<
diff
.
getComponents
(
root
)
<<
std
::
endl
;
std
::
cout
<<
"p2-p1 components in cs2: "
<<
diff
.
getComponents
(
cs2
)
<<
std
::
endl
;
// by definition invariant under translations
std
::
cout
<<
"p2-p1 components in cs3: "
<<
diff
.
getComponents
(
cs3
)
<<
std
::
endl
;
// but not under rotations
std
::
cout
<<
"p2-p1 norm^2: "
<<
norm
<<
std
::
endl
;
std
::
cout
<<
"p2-p1 norm^2: "
<<
norm
<<
std
::
endl
;
Sphere
s
(
p1
,
10
_m
);
Sphere
s
(
p1
,
10
_m
);
// define a sphere around a point with a radius
std
::
cout
<<
"p1 inside s: "
<<
s
.
isInside
(
p2
)
<<
std
::
endl
;
//~ std::cout << "p1 inside s: " << s.isInside(p2) << std::endl;
Sphere
s2
(
p1
,
3
_um
);
// another sphere
//~ std::cout << "p1 inside s2: " << s2.isInside(p2) << std::endl;
// let's try parallel projections:
auto
const
v1
=
Vector
<
length_d
>
(
root
,
{
1
_m
,
1
_m
,
0
_m
});
auto
const
v2
=
Vector
<
length_d
>
(
root
,
{
1
_m
,
0
_m
,
0
_m
});
auto
const
v3
=
v1
.
parallelProjectionOnto
(
v2
);
auto
const
cross
=
v1
.
cross
(
v2
).
normalized
();
Sphere
s2
(
p1
,
3
_um
);
// if a CS is not given as parameter for getComponents(), the components
std
::
cout
<<
"p1 inside s2: "
<<
s2
.
isInside
(
p2
)
<<
std
::
endl
;
// in the "home" CS are returned
std
::
cout
<<
v1
.
getComponents
()
<<
std
::
endl
;
std
::
cout
<<
v2
.
getComponents
()
<<
std
::
endl
;
std
::
cout
<<
v3
.
getComponents
()
<<
std
::
endl
;
std
::
cout
<<
cross
.
getComponents
()
<<
std
::
endl
;
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment