return x_values, y_values witch works but I have a proble, the end part of the atan curves out of my graph, I need a something that start as atan and ends straight
Assistant
User
yes this is in the good direction blend_weights = np.linspace(1, -1, FREQ)
y_values = (1 - blend_weights) * y_values_atan + blend_weights * y_values_linear but this curves the begining of the graph, not the end
Assistant
To ensure that the end of your curve aligns more closely with a straight line, you can smoothly transition from the arctangent function to a linear function. One way to achieve this is by blending the arctangent curve with a linear curve toward the end of your domain. Here's an approach that could help achieve what you're looking for:
Define a blending factor that gradually increases as you move towards the end of the domain.
Use the blending factor to add a straight line contribution to the arctangent curve.
Here's a modified version of your function incorporating these ideas:
python
import numpy as np
def stop_approach_phase(start_time, gradient, blend_factor=0.9):
# Calculate the length based on the gradient
length = abs(GPP + DMAX) / abs(gradient)
# Generate x values within the specified range
x_values = np.linspace(start_time, start_time + length, FREQ)
# Normalized range for arctan computation
normalized_x = np.linspace(-1, 1, FREQ)
# Compute arctan and normalize it
scaled_atan = np.arctan(3 * normalized_x)
atan_min, atan_max = scaled_atan.min(), scaled_atan.max()
y_values_atan = DMAX + (scaled_atan - atan_min) / (atan_max - atan_min) * (-DMAX)
# Linear part starting value (corresponds to final part of atan)
linear_start = y_values_atan[-1]
# Generate a linear decrease from this value towards zero
y_values_linear = np.linspace(linear_start, 0, FREQ)
# Blend the arctan and linear parts
blend_weights = np.linspace(blend_factor, 1, FREQ)
y_values = (1 - blend_weights) * y_values_atan + blend_weights * y_values_linear
return x_values, y_values
# Constants for your specific graph (replace with your actual constants)
GPP = 10 # Example value
DMAX = 5 # Example value
FREQ = 100 # Example value for the number of points
start_time = 0 # Start time for the graph
gradient = 1 # Example gradient
# Usage example
x, y = stop_approach_phase(start_time, gradient)
Explanation:
Blend Factor: This parameter determines how much of the straight line is mixed with the arctan curve. A value of 0.9 will make the end part more linear, but you can adjust this factor to suit your needs; lower values will keep more of the arctan shape.
Linear Contribution: We calculate a linear curve from the ending arctan value down towards zero and blend this with the tail of the arctan curve using the blend factor.
Adjust the blend_factor to control how "straight" the end of the curve should be, ensuring it fits within your plot's constraints.
To ensure that the beginning of the graph retains the arctangent shape and the end transitions smoothly to a straight line, you should configure the blend weights in reverse. This means starting with no contribution from the linear part and smoothly transitioning to full contribution at the end.
To do this, you should linearly increase the contribution of the linear part from 0 to 1 as you traverse through the x-values. Here’s how you can modify your function:
python
import numpy as np
def stop_approach_phase(start_time, gradient, blend_factor=0.9):
# Calculate the length based on the gradient
length = abs(GPP + DMAX) / abs(gradient)
# Generate x values within the specified range
x_values = np.linspace(start_time, start_time + length, FREQ)
# Normalized range for arctan computation
normalized_x = np.linspace(-1, 1, FREQ)
# Compute arctan and normalize it
scaled_atan = np.arctan(3 * normalized_x)
atan_min, atan_max = scaled_atan.min(), scaled_atan.max()
y_values_atan = DMAX + (scaled_atan - atan_min) / (atan_max - atan_min) * (-DMAX)
# Linear part starting value (corresponds to final part of arctan at the beginning)
linear_start = y_values_atan[-1]
# Generate a linear decrease from this value towards zero
y_values_linear = np.linspace(linear_start, 0, FREQ)
# Reverse blend weights: starts with 0 (all arctan) end with 1 (all linear)
blend_weights = np.linspace(0, 1 - blend_factor, FREQ)
# Blend the arctan and linear parts
y_values = (1 - blend_weights) * y_values_atan + blend_weights * y_values_linear
return x_values, y_values
# Constants for your specific graph (replace with your actual constants)
GPP = 10 # Example value
DMAX = 5 # Example value
FREQ = 100 # Example value for the number of points
start_time = 0 # Start time for the graph
gradient = 1 # Example gradient
# Usage example
x, y = stop_approach_phase(start_time, gradient)
Explanation:
Blend Weights: The blend_weights array starts from 0 (no contribution from the linear curve) to gradually increase to just under 1 - blend_factor. This means the start of the curve is primarily arctan, and it softly transitions to become linear towards the end.
Contribution Proportions: y_values is calculated by mixing the arctan and linear parts according to the weights. This ensures the start is predominantly arctan, and towards the end, the curve blends smoothly into the straight line.
By adjusting the blend_factor, you control how much influence the linear part has towards the end, allowing you to get the desired straight-line extension without affecting the initial arctan characteristic.