Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
Interactive model comparison
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Albin Heimerson
Interactive model comparison
Commits
38e60dc7
Commit
38e60dc7
authored
Dec 6, 2022
by
Martin Morin
Browse files
Options
Downloads
Patches
Plain Diff
Add second order pole dragging
parent
d083b5ef
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib.rs
+1
-15
1 addition, 15 deletions
src/lib.rs
src/transfer_functions.rs
+34
-1
34 additions, 1 deletion
src/transfer_functions.rs
with
35 additions
and
16 deletions
src/lib.rs
+
1
−
15
View file @
38e60dc7
...
@@ -161,21 +161,7 @@ mod pole_position_app {
...
@@ -161,21 +161,7 @@ mod pole_position_app {
// Handle dragging
// Handle dragging
if
dragged
{
if
dragged
{
let
(
re_off
,
im_off
)
=
match
self
.pole_drag_offset
{
if
let
Some
((
re
,
im
))
=
pointer_coordinate
{
// This should never fail
Some
((
x
,
y
))
=>
(
x
,
y
),
None
=>
{
// We have just started to drag, find offset to closest pole so we don't jump
//
// For now, just assume we want to place the pole where we click
self
.pole_drag_offset
=
Some
((
0.0
,
0.0
));
(
0.0
,
0.0
)
}
};
if
let
Some
((
re
,
im
))
=
pointer_coordinate
{
// This should never fail
let
(
re
,
im
)
=
(
re
+
re_off
,
im
+
im_off
);
match
self
.order
{
match
self
.order
{
Order
::
First
=>
self
.fo
.adjust_poles_to
(
re
,
im
),
Order
::
First
=>
self
.fo
.adjust_poles_to
(
re
,
im
),
Order
::
Second
=>
self
.so
.adjust_poles_to
(
re
,
im
),
Order
::
Second
=>
self
.so
.adjust_poles_to
(
re
,
im
),
...
...
...
...
This diff is collapsed.
Click to expand it.
src/transfer_functions.rs
+
34
−
1
View file @
38e60dc7
...
@@ -127,5 +127,38 @@ impl TransferFunction for SecondOrderSystem {
...
@@ -127,5 +127,38 @@ impl TransferFunction for SecondOrderSystem {
}
}
}
}
fn
adjust_poles_to
(
&
mut
self
,
_re
:
f64
,
_im
:
f64
)
{}
fn
adjust_poles_to
(
&
mut
self
,
re
:
f64
,
im
:
f64
)
{
if
re
>=
0.0
{
return
}
let
mut
d_new
=
self
.d
;
let
w_new
;
if
self
.d
<
1.0
{
// two complex poles
let
(
re2
,
im2
)
=
(
re
.powi
(
2
),
im
.powi
(
2
));
d_new
=
(
re2
/
(
re2
+
im2
))
.sqrt
();
w_new
=
-
re
/
d_new
;
}
else
if
self
.d
==
1.0
{
w_new
=
-
re
;
// real double pole
}
else
{
// two real poles
let
d2
=
self
.d
.powi
(
2
);
let
fast
=
-
self
.d
*
self
.w
+
self
.w
*
(
d2
-
1.0
)
.sqrt
();
let
slow
=
-
self
.d
*
self
.w
-
self
.w
*
(
d2
-
1.0
)
.sqrt
();
if
(
re
-
fast
)
.abs
()
<
(
re
-
slow
)
.abs
()
{
w_new
=
re
/
(
-
self
.d
+
(
d2
-
1.0
)
.sqrt
()
);
}
else
{
w_new
=
re
/
(
-
self
.d
-
(
d2
-
1.0
)
.sqrt
()
);
}
}
if
self
.d_lower
<=
d_new
&&
self
.d_upper
>=
d_new
&&
self
.w_lower
<=
w_new
&&
self
.w_upper
>=
w_new
{
self
.d
=
d_new
;
self
.w
=
w_new
;
}
}
}
}
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