Skip to content

Commit

Permalink
Add scaling factor (#293)
Browse files Browse the repository at this point in the history
* Add scaling factor

* Update changelog

* Fix deepsource issue

* fix pydocstyle issue

* update CHANGELOG.md

Co-authored-by: Cagtay Fabry <[email protected]>
  • Loading branch information
vhirtham and CagtayFabry authored Mar 21, 2021
1 parent ee85f64 commit 93b3e1f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Notes

## 0.3.1 (unreleased)
## 0.3.1 (21.03.2021)

### added

Expand All @@ -20,6 +20,8 @@
[[#291]](https://github.com/BAMWelDX/weldx/pull/291)
- use `pint` compatible array syntax in `IsoBaseGroove.to_profile()`
methods [[#189]](https://github.com/BAMWelDX/weldx/pull/189)
- CSM and LCS plot function get a `scale_vectors` parameter. It scales the plotted coordinate system vectors when using
matplotlib as backend [[#293]](https://github.com/BAMWelDX/weldx/pull/293)

### fixes

Expand Down
5 changes: 5 additions & 0 deletions weldx/transformations/cs_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,7 @@ def plot(
time: types_time_and_lcs = None,
time_ref: pd.Timestamp = None,
axes_equal: bool = False,
scale_vectors: Union[float, List, np.ndarray] = None,
show_data_labels: bool = True,
show_labels: bool = True,
show_origins: bool = True,
Expand Down Expand Up @@ -1793,6 +1794,9 @@ def plot(
axes_equal :
(matplotlib only) If `True`, all axes are adjusted to cover an equally large
range of value. That doesn't mean, that the limits are identical
scale_vectors :
(matplotlib only) A scaling factor or array to adjust the length of the
coordinate system vectors
show_data_labels :
(k3d only) If `True`, plotted data sets get labels with their names attached
to them
Expand Down Expand Up @@ -1850,6 +1854,7 @@ def plot(
title=title,
limits=limits,
set_axes_equal=axes_equal,
scale_vectors=scale_vectors,
show_origins=show_origins,
show_trace=show_traces,
show_vectors=show_vectors,
Expand Down
6 changes: 5 additions & 1 deletion weldx/transformations/local_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import warnings
from copy import deepcopy
from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING, List, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -836,6 +836,7 @@ def plot(
time: types_time_and_lcs = None,
time_ref: pd.Timestamp = None,
time_index: int = None,
scale_vectors: Union[float, List, np.ndarray] = None,
show_origin: bool = True,
show_trace: bool = True,
show_vectors: bool = True,
Expand Down Expand Up @@ -863,6 +864,8 @@ def plot(
time_index: int
If the coordinate system is time dependent, this parameter can be used to
to select a specific key frame by its index.
scale_vectors :
A scaling factor or array to adjust the vector length
show_origin: bool
If `True`, a small dot with the assigned color will mark the coordinate
systems' origin.
Expand All @@ -883,6 +886,7 @@ def plot(
time=time,
time_ref=time_ref,
time_index=time_index,
scale_vectors=scale_vectors,
show_origin=show_origin,
show_trace=show_trace,
show_vectors=show_vectors,
Expand Down
33 changes: 29 additions & 4 deletions weldx/visualization/matplotlib_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def draw_coordinate_system_matplotlib(
color: Any = None,
label: str = None,
time_idx: int = None,
scale_vectors: Union[float, List, np.ndarray] = None,
show_origin: bool = True,
show_vectors: bool = True,
):
Expand All @@ -115,6 +116,8 @@ def draw_coordinate_system_matplotlib(
time_idx :
Selects time dependent data by index if the coordinate system has
a time dependency.
scale_vectors :
A scaling factor or array to adjust the vector length
show_origin :
If `True`, the origin of the coordinate system will be highlighted in the
color passed as another parameter
Expand All @@ -137,10 +140,23 @@ def draw_coordinate_system_matplotlib(
p_0 = dsx.coordinates

if show_vectors:
orientation = dsx.orientation
p_x = p_0 + orientation[:, 0]
p_y = p_0 + orientation[:, 1]
p_z = p_0 + orientation[:, 2]
if scale_vectors is None:
tips = dsx.orientation
else:
if not isinstance(scale_vectors, np.ndarray):
if isinstance(scale_vectors, List):
scale_vectors = np.array(scale_vectors)
else:
scale_vectors = np.array([scale_vectors for _ in range(3)])

scale_mat = np.eye(3, 3)
for i in range(3):
scale_mat[i, i] = scale_vectors[i]
tips = np.matmul(scale_mat, dsx.orientation.data)

p_x = p_0 + tips[:, 0]
p_y = p_0 + tips[:, 1]
p_z = p_0 + tips[:, 2]

axes.plot([p_0[0], p_x[0]], [p_0[1], p_x[1]], [p_0[2], p_x[2]], "r")
axes.plot([p_0[0], p_y[0]], [p_0[1], p_y[1]], [p_0[2], p_y[2]], "g")
Expand All @@ -160,6 +176,7 @@ def plot_local_coordinate_system_matplotlib(
time: types_timeindex = None,
time_ref: pd.Timestamp = None,
time_index: int = None,
scale_vectors: Union[float, List, np.ndarray] = None,
show_origin: bool = True,
show_trace: bool = True,
show_vectors: bool = True,
Expand All @@ -183,6 +200,8 @@ def plot_local_coordinate_system_matplotlib(
`pandas.TimedeltaIndex`
time_index :
Index of a specific time step that should be plotted
scale_vectors :
A scaling factor or array to adjust the vector length
show_origin :
If `True`, the origin of the coordinate system will be highlighted in the
color passed as another parameter
Expand Down Expand Up @@ -212,6 +231,7 @@ def plot_local_coordinate_system_matplotlib(
color=color,
label=label,
time_idx=i,
scale_vectors=scale_vectors,
show_origin=show_origin,
show_vectors=show_vectors,
)
Expand All @@ -223,6 +243,7 @@ def plot_local_coordinate_system_matplotlib(
color=color,
label=label,
time_idx=time_index,
scale_vectors=scale_vectors,
show_origin=show_origin,
show_vectors=show_vectors,
)
Expand Down Expand Up @@ -333,6 +354,7 @@ def plot_coordinate_system_manager_matplotlib(
time_ref: pd.Timestamp = None,
title: str = None,
limits: types_limits = None,
scale_vectors: Union[float, List, np.ndarray] = None,
set_axes_equal: bool = False,
show_origins: bool = True,
show_trace: bool = True,
Expand Down Expand Up @@ -374,6 +396,8 @@ def plot_coordinate_system_manager_matplotlib(
Each tuple marks lower and upper boundary of the x, y and z axis. If only a
single tuple is passed, the boundaries are used for all axis. If `None`
is provided, the axis are adjusted to be of equal length.
scale_vectors :
A scaling factor or array to adjust the length of the coordinate system vectors
set_axes_equal :
(matplotlib only) If `True`, all axes are adjusted to cover an equally large
range of value. That doesn't mean, that the limits are identical
Expand Down Expand Up @@ -428,6 +452,7 @@ def plot_coordinate_system_manager_matplotlib(
axes=axes,
color=color,
label=lcs_name,
scale_vectors=scale_vectors,
show_origin=show_origins,
show_trace=show_trace,
show_vectors=show_vectors,
Expand Down

0 comments on commit 93b3e1f

Please sign in to comment.