Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ronan
coraMaths
Commits
66bd89ff
Commit
66bd89ff
authored
Jun 06, 2016
by
ronan
Browse files
Add Interpolation method
parent
4eac07c4
Pipeline
#2261
passed with stage
in 1 minute and 7 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cora/cora-maths/1.0/cora-maths-1.0-javadoc.jar
View file @
66bd89ff
No preview for this file type
cora/cora-maths/1.0/cora-maths-1.0-sources.jar
View file @
66bd89ff
No preview for this file type
cora/cora-maths/1.0/cora-maths-1.0.jar
View file @
66bd89ff
No preview for this file type
src/main/java/org/cora/maths/utils/Interpolation.java
0 → 100644
View file @
66bd89ff
package
org.cora.maths.utils
;
/**
* Created by ronan-j on 06/06/16.
*/
public
class
Interpolation
{
/**
* Compute linear interpolation value
* @param start start value
* @param end end value
* @param duration full animation duration
* @param time current time
* @return computed value
*/
public
static
float
linearInterpolation
(
float
start
,
float
end
,
float
duration
,
float
time
)
{
// y = ax + b
float
b
=
start
;
float
a
=
(
end
-
start
)
/
duration
;
return
a
*
time
+
b
;
}
/**
* Compute exponentiel interpolation value
* @param start start value
* @param end end value
* @param duration full animation duration
* @param time current time
* @param k base of exp
* @return computed value
*/
public
static
float
expInterpolation
(
float
start
,
float
end
,
float
duration
,
float
time
,
float
k
)
{
// y = a * exp(bkx)
float
a
=
start
;
float
b
=
(
float
)
(
Math
.
log
(
end
/
a
)
/
(
k
*
duration
));
return
(
float
)
(
a
*
Math
.
exp
(
b
*
k
*
time
));
}
/**
* Compute logarithmic interpolation value
* @param start start value
* @param end end value
* @param duration full animation duration
* @param time current time
* @param k base of log
* @return computed value
*/
public
static
float
logInterpolation
(
float
start
,
float
end
,
float
duration
,
float
time
,
float
k
)
{
// y = a + b * log(kx)
float
r
=
1
/
k
;
start
+=
r
;
duration
+=
r
;
time
+=
r
;
float
a
=
start
;
float
b
=
(
float
)
((
end
-
a
)
/
Math
.
log
(
k
*
duration
+
1
));
return
(
float
)
(
a
+
b
*
Math
.
log
(
k
*
time
));
}
/**
* Compute exponentiel interpolation value
* @param start start value
* @param end end value
* @param duration full animation duration
* @param time current time
* @param x x pow value
* @param k base of pow
* @return computed value
*/
public
static
float
powInterpolation
(
float
start
,
float
end
,
float
duration
,
float
time
,
float
x
,
float
k
)
{
// y = a * x^(bkx)
float
a
=
start
;
float
b
=
(
float
)
(
Math
.
log
(
end
/
a
)
/
(
k
*
duration
*
Math
.
log
(
x
)));
return
(
float
)
(
a
*
Math
.
pow
(
x
,
b
*
k
*
time
));
}
}
Write
Preview
Supports
Markdown
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