Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bbguimaraes
college
Commits
b09e2c65
Commit
b09e2c65
authored
Jul 16, 2016
by
bbguimaraes
Browse files
sms: optimize spring force calculation
parent
30d46db1
Changes
1
Hide whitespace changes
Inline
Side-by-side
sms/libsms/src/spring.cpp
View file @
b09e2c65
...
...
@@ -3,10 +3,8 @@
void
Spring
::
update_force
()
{
this
->
m_distance
=
this
->
mass1
()
->
position
()
-
this
->
mass0
()
->
position
();
float
displacement
=
this
->
distance
().
magnitude
()
-
this
->
eq_length
()
;
const
float
DISTANCE_MAG
=
this
->
distance
().
magnitude
();
// Hooke's law: F = kX
float
force
=
this
->
k
()
*
displacement
;
// TODO remove normalization?
// can the force be derived from the original value of distance?
this
->
m_force
=
this
->
distance
().
normalized
().
scaled
(
-
force
);
float
force
=
this
->
k
()
*
(
DISTANCE_MAG
-
this
->
eq_length
());
this
->
m_force
=
this
->
distance
().
scaled
(
-
force
/
DISTANCE_MAG
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment