I want to generate a sine wave from 2 data points, tmin
and tmax
. where tmin
is where the sin wave starts, and the tmax
is the top most point of the sine wave.
Then I want to find where tbase
and tlimit
intersect with the sine wave created in the previous step.
Example.
C = tlimit
B = tbase
I want to find area’s 1
and 2
(as in the example image)
currently, I’m able to calculate the area when tlimit
is above tmax
and tbase
is less than or equal to tmin
, just need help with this. here are my existing code but it may be wrong.
Existing Code
const calculateArea = (amplitude, meanTemp, threshold, start, end, steps = 1000) => {
const dx = (end - start) / steps;
let area = 0;
for (let i = 0; i < steps; i++) {
const x = start + (i * dx);
const y = amplitude * Math.sin(x) + meanTemp;
if (y > threshold) {
const areaToAdd = (y - threshold) * dx;
area += areaToAdd;
}
}
return area;
}
// Called like
const tmean = (tmax + tmin) / 2;
const amplitude = (tmax - tmin) / 2;
const start = 0;
const end = 2 * Math.PI;
const area = calculateAreaThreshold(amplitude, tmean, tbase, start, end)
Test data (with results that may be wrong)
# Test Data 1
tmin = 5
tmax = 25
tbase = 10
tlimit = 30
current_returned_result = 39.610976908929906
# Test Data 2
tmin = 5
tmax = 25
tbase = 20
tlimit = 30
current_returned_result = 7.527554726471326
# Test Data 3
tmin = 5
tmax = 25
tbase = 15
tlimit = 22
current_returned_result = 24.679341500413543
I’ve been watching videos from Khan Academy
on YT, about AP Calculus
but I’m super lost