Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flatland
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
yoogottamk
Flatland
Commits
6533d618
Commit
6533d618
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
81711bf7
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
examples/Simple_Realistic_Railway_Generator.py
+86
-0
86 additions, 0 deletions
examples/Simple_Realistic_Railway_Generator.py
with
86 additions
and
0 deletions
examples/Simple_Realistic_Railway_Generator.py
+
86
−
0
View file @
6533d618
...
...
@@ -15,36 +15,122 @@ from flatland.utils.rendertools import RenderTool
class
PositionOps
:
def
subtract_pos
(
nodeA
,
nodeB
):
"""
vector operation : nodeA - nodeB
:param nodeA: tuple with coordinate (x,y) or 2d vector
:param nodeB: tuple with coordinate (x,y) or 2d vector
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
(
nodeA
[
0
]
-
nodeB
[
0
],
nodeA
[
1
]
-
nodeB
[
1
])
def
add_pos
(
nodeA
,
nodeB
):
"""
vector operation : nodeA + nodeB
:param nodeA: tuple with coordinate (x,y) or 2d vector
:param nodeB: tuple with coordinate (x,y) or 2d vector
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
(
nodeA
[
0
]
+
nodeB
[
0
],
nodeA
[
1
]
+
nodeB
[
1
])
def
make_orthogonal_pos
(
node
):
"""
vector operation : rotates the 2D vector +90°
:param node: tuple with coordinate (x,y) or 2d vector
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
(
node
[
1
],
-
node
[
0
])
def
get_norm_pos
(
node
):
"""
calculates the euclidean norm of the 2d vector
:param node: tuple with coordinate (x,y) or 2d vector
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
np
.
sqrt
(
node
[
0
]
*
node
[
0
]
+
node
[
1
]
*
node
[
1
])
def
normalize_pos
(
node
):
"""
normalize the 2d vector = v/|v|
:param node: tuple with coordinate (x,y) or 2d vector
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
n
=
PositionOps
.
get_norm_pos
(
node
)
if
n
>
0.0
:
n
=
1
/
n
return
PositionOps
.
scale_pos
(
node
,
n
)
def
scale_pos
(
node
,
scalar
):
"""
scales the 2d vector = node * scale
:param node: tuple with coordinate (x,y) or 2d vector
:param scale: scalar to scale
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
(
node
[
0
]
*
scalar
,
node
[
1
]
*
scalar
)
def
round_pos
(
node
):
"""
rounds the x and y coordinate and convert them to an integer values
:param node: tuple with coordinate (x,y) or 2d vector
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
(
int
(
np
.
round
(
node
[
0
])),
int
(
np
.
round
(
node
[
1
])))
def
ceil_pos
(
node
):
"""
ceiling the x and y coordinate and convert them to an integer values
:param node: tuple with coordinate (x,y) or 2d vector
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
(
int
(
np
.
ceil
(
node
[
0
])),
int
(
np
.
ceil
(
node
[
1
])))
def
bound_pos
(
node
,
min_value
,
max_value
):
"""
force the values x and y to be between min_value and max_value
:param node: tuple with coordinate (x,y) or 2d vector
:param min_value: scalar value
:param max_value: scalar value
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
return
(
max
(
min_value
,
min
(
max_value
,
node
[
0
])),
max
(
min_value
,
min
(
max_value
,
node
[
1
])))
def
rotate_pos
(
node
,
rot_in_degree
):
"""
rotate the 2d vector with given angle in degree
:param node: tuple with coordinate (x,y) or 2d vector
:param rot_in_degree: angle in degree
:return:
-------
tuple with coordinate (x,y) or 2d vector
"""
alpha
=
rot_in_degree
/
180.0
*
np
.
pi
x0
=
node
[
0
]
y0
=
node
[
1
]
...
...
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