 # Thread: Maths Problem - Line Function

1. ## Maths Problem - Line Function

I need to draw a very particular kind of line (approximating it using a logarithmic curve is not going to be sufficient). Any help would be very gratefully appreciated! The line will be straight from 0,0 to Point_A.

It will be a curve from Point_A to 1,1.
The gradient of this curved section will initally be the same as the gradient of the straight section, but will decrease gradually (linearly), reaching 0 when x=1.

Point_A will always have X and Y coordinates in the range 0 to 1.
Point_A will also always be above the straight line from 0,0 to 1,1 (ie. in the half of the chart shaded darker), in case that makes a difference.

For any value of X between 0 and 1, I need a formula to calculate Y.
In fact, it really just needs to be for any vaue of X between Ax and 1, since the straight section is relatively trivial. Here's what I've tried so far...
I'm extending the line from 0,0 to A, to find the value of Y when X is 1 (see the pink line).
When X=1, Y = Ay / Ax
eg. Y = 0.5 / 0.25 = 2

The pink straight line is always above the ideal curved line, but by how much? (see Line_D)
I know that when X=1, the difference between the Y values of my straight line and my ideal curved line is Ay / Ax (which is 2 in this example) .
At X=Ax, the difference is 0.
For any given point between them, the difference will be somewhere between - but it doesn't seem to be a linear relationship.

For any given point on the line (Point_P), I'm finding Px - Ax (Line_B), and expressing it as a proportion of 1 - Ax (Line_C).
B = (Px - Ax) / (1 - Ax)

When Px=Ax, B=0.
When Px=1, B=1.

If I raise B to the power of 1.5, and subtract that from the straightline formula, I get the correct result here - but it only holds true for this example (I only arrived at the value of 1.5 through trial and error).
eg. If X=0.5,
B = (0.5 - 0.25) / (1 - 0.25) = 0.33333
B ^ 1.5 = 0.19245
Y = (0.5 * 0.5 / 0.25) - 0.19245 = 0.80755

So, how on Earth do I calculate the right exponent to use for any given position of Point_A?
Or am I doing something totally wrong to begin with?  Reply With Quote

2. Not sure how much help I’ll be Muddy
But I was thinking you might be able to simplify things a bit
Attachment 28390

Have you been using desmos?

Also this video is a pretty good watch
3:40:00 ish I think
https://youtu.be/yg6h4XQqPNQ  Reply With Quote

3. Thanks - that's an interesting link It turns out that what I wanted is actually physically impossible. There's precisely one location of Point_A where it is possible to reach an end point of 1,1 and gradient of zero, using a constant change of angle - in every other case, it's possible to get either the correct end point, or the correct end gradient, but not both.

I asked the same question on a couple of maths forums, and a user by the name of Dr.Peterson ( freemathhelp.com ) was kind enough to provide me with a solution that I think will be good enough for my purposes: https://www.desmos.com/calculator/ehtele1rsf

That was actually the first time I've come across Desmos, but it seems pretty useful, so I may look into it a bit more. I also like Wolfram Alpha for simplifying complicated formulas, although I'm slightly torn on whether that's even a good idea (a simpler formula is neater and faster, but if I come back to it months later, it won't be obvious how I derived it).  Reply With Quote

4. We live in dark times when the Fusion guru himself needs to ask for help! Sounds like you've got what you need, but but I thought I'd also mention a program I've been using myself recently called Curve Expert. I use it to create Polynomial curves from data points, and it's pretty good. It can also create many other types of curves - Bleasdale curves, tension splines, DR-Multistage-2-Zerobackground, and all sorts of other gobbledygook - so perhaps it can do the 'hockey stick' type that you're after.  Reply With Quote

5. Haha, thanks.
That looks interesting - probably overkill for my little curve. I think the solution I have now will work, but also, I'm beginning to think that even just approximating a curve using 2 or 3 straight line segments will be good enough, and might better fit the general retro aesthetic.
It was going to be for a 7-day-roguelike (7drl) gamejam entrant, but I'm never going to finish it in time now anyway - I spent way too long on the most pointless things! I should probably try to finish it off though...  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•