# Help needed with algebra calculator

@CodeHelp 2 problems have come to my attention:

1. The grater the distance between the 2 points, the less accurate the line of best fit.
2. If the line of best fit hits the top or bottom of the graph before the edge, it won’t continue forming the line.

Any help will be given credit for. Thanks!

14 Likes

How and in which object do you figure out the line of best fit?

7 Likes

This could be a rounding issue with set position. Instead of using the default x and y position variables, make your own, which can be more precise, and set position to those.

Do you want to use trail art anywhere other than the graph?

6 Likes

@Petrichor is correct. The problem is accumulation of rounding error in the Set Position steps.

First, 1 long line is drawn between the 2 points. That part of the line is drawn accurately (since you rounded the Last Touched locations to be exact points on the graph). Subsequently, the remainder of the line is drawn in small steps. Each one of those small steps accumulates a small error as the Set Position block rounds the position to the nearest pixel.

There’s multiple approaches to fixing the issue

1. As Petrichor said, implement 2 new variables to track the X & Y locations of each small step more precisely. I’d speculate that this is a more complicated approach.
2. Calculate where the line crosses the outer bounds of the graph. Draw 1 single line between these two points. Those points will still get rounded by the Set Position to the nearest pixel, but that won’t be noticeable. This is what I’d recommend.
6 Likes

I don’t think so.

3 Likes

Ok. Thanks. I will implement the second option.

2 Likes

Then the simplest option would be covering everything else with objects, although if you change the method of drawing the line, you may b not need to.

3 Likes

Ok. I’ll see what I end up doing. Could I use the same code for the x boundary as the y boundary do you think?

2 Likes

Probably. I’m not sure what you’re using now but it should be basically the same but vertical.

3 Likes

Ok. I’ll see if that works.

2 Likes

bump

Pls stop bumping topics that have nothing to do with wut the hser is doing rn

2 Likes