The Wiki for Tale 5 is in read-only mode and is available for archival and reference purposes only. Please visit the current Tale 11 Wiki in the meantime.

If you have any issues with this Wiki, please post in #wiki-editing on Discord or contact Brad in-game.

User:McArine/Incense

From ATITD5
Jump to navigationJump to search

My approach to determining incense coordinates

For a long time I tried to find optimum coordinates, by doing exhaustive searches, that would fit the best.
But seeing that none of my results were any good, I considered other approaches.

In T4 the formula for calculating incense qualities was found, and we can see that it hasn't changed in T5.
The current location in simple form:

     7*Sx + n*Rx
Xn = ------------
       7 + n       

     7*Sy + n*Ry
Yn = ------------
       7 + n 

This is the current location between Startpoint and Resinpoint, where n is the amount of resin added.
This gives us a string of locations that are dependent upon the Start and Resin points.
At each of these points we have a quality measure, and an attribute, that indicates to us, how far we are from that closest attribute.

As we don't know the location of the Attribute point, we don't know how far away it is, we just know how much closer to, or further away from the point we get, each time we add a deben of resin.
So that was initially what I used to calculate locations, the difference in quality, between two deben of resin.
And the maths for this gets a bit hairy, I can tell you.

Then one day, I drew something like this:
IncenseA1.png

And realised that I had a lot of right angle triangles in this image. I didn't know the exact location where the circle intersected the line, because I didn't know the size of the circle... So what's good about this.

Well, realizing this you can build a simpler program, that can figure out the distance between Start and Resin points. Can calculate where the Attribute point is closest, at what distance it is from the line between Start and Resin points. And another cool thing, you can get how far from the start attribute, the start point is. And these things helps us a lot.
Where you previously brute forced through a lot of coordinates, without much accuracy. This approach can be done with three loops, in a program. But you don't know any boundaries for those loops.
The new approach also takes three loops. But the range these cover is a lot smaller. The first loop varies the distance between Start and Resin point(we assume they're both on the x-axis, and that the Start point is at 0,0). The second loop varies between the two maximum quality values, that's where we have the closest point. The third loop varies the distance from the Attribute to the Start-Resin line, this value will (allways, because Teppy likes the Floor function) be larger than the highest quality value of that Attribute.
I know that using a value equal to or larger than the best quality, doesn't give you the distance from the line to the Attribute point. But with a bit of math we don't need it, we just need to know the difference between that value and the quality value we use on the hypotenuse.
Now, with the closest point, the distance to the Attibute, and the quality of the other points, we can calculate a lot of pythogerean triangles. Compare the resulting values, and see if the location we have found is a good match.

The math is like this:

a² + b² = c²

Where a is the estimated distance between your (Xn, Yn) and the intersection of the circle and the line.
b is the distance from the intersection to the circle center.
And c is the distance between the (Xn, Yn) and the circle center.

Now a is depending on the distance between S and R, and also on the intersection, which is also depending on the distance between S and R. (and we need to try all locations between the two maximum quality points.)
b is the radius of the circle: r. c is the radius of the circle, plus the difference in quality from (Xn, Yn) to the center(Dq). And we have a good estimate of this.

So the formula becomes:

a² + r² = (Dq + r)²

This can be transformed into

    a² + Dq²
r = --------
     2*Dq

And for each n location on the line between R and S, that had the same closest attribute. rn can be calculated, and compared to the others, until the best location is found.

Using this formula I can calculate a very good location in less than 1 second, with 0.1 accuracy. This would take hours using my first approach.

Some notes: this works best when using values that differ by more than 20 from start to max.
The formula does not figure out if the actual location of A is positive or negative.
I don't have a minimum requirement for number of locations for calculating using this approach, but I've had good results using 7 points.