Simple fix for the ugly rail circles
Moderator: ickputzdirwech
Simple fix for the ugly rail circles
I find this so interesting, that I link it to the suggestions board, even knowing, that this is not really a suggestion. -- ssilk
Soo, this is not a proper circle.
Why do there need to be straight segments in the diagonals? No one expects this, this shouldn't be neccessary.
You probably have no desire reworking the entire geometry (e.g. as needed to incorporate s-bends, which is surprisingly complicated), and you don't have to. The fix is really easy. Here it is: So the curve segment has a 10 tile radius, which means a 7% deviation to meet the diagonal, not a bad choice. (12 would be only 1,2%, but as I promised, no reworking today - I will open a thread in ideas and suggestions for that.) Rail segments are subject to placement restrictions, to reduce the clutter and chance of near miss while building I guess. Sensible restriction.
But with that, a completely unnecessary problem was introduced. If the horizontal and vertical segments should end only at every second grid line (thick line), then the center of the circle has to be positiond on a thick line crossing. But with a radius of 10, this means that the horizontal and vertical segments themselves, have to be positiond right on top a thick line, not a thin one.
So simply swapping the placement restrictions, alleviates the need for straight segments in the circle, while preserving every other property. It would even be possible to make the diagonals twice as long, since every curves diagonal end then ends on a thin line crossing, never on a thick one. The graphics already suggest that length.
I really am puzzled as to why the current geometry is this way, as I see no need or reason(*) for it. So I guess it really is unintentionally.
Savegame compatibility would be broken, obviously.
* Only perhaps, that in this configuration, a two track line without space in between aims right for the center of a upcoming circle. With the fix, a single track may be centered towards the circle, two tracks without space would always be off, as one track will be centered, the other not.
Edit: Changed the subject. "Simple fix for flawed rail geometry" seems to have caused some misunderstandings.
Soo, this is not a proper circle.
Why do there need to be straight segments in the diagonals? No one expects this, this shouldn't be neccessary.
You probably have no desire reworking the entire geometry (e.g. as needed to incorporate s-bends, which is surprisingly complicated), and you don't have to. The fix is really easy. Here it is: So the curve segment has a 10 tile radius, which means a 7% deviation to meet the diagonal, not a bad choice. (12 would be only 1,2%, but as I promised, no reworking today - I will open a thread in ideas and suggestions for that.) Rail segments are subject to placement restrictions, to reduce the clutter and chance of near miss while building I guess. Sensible restriction.
But with that, a completely unnecessary problem was introduced. If the horizontal and vertical segments should end only at every second grid line (thick line), then the center of the circle has to be positiond on a thick line crossing. But with a radius of 10, this means that the horizontal and vertical segments themselves, have to be positiond right on top a thick line, not a thin one.
So simply swapping the placement restrictions, alleviates the need for straight segments in the circle, while preserving every other property. It would even be possible to make the diagonals twice as long, since every curves diagonal end then ends on a thin line crossing, never on a thick one. The graphics already suggest that length.
I really am puzzled as to why the current geometry is this way, as I see no need or reason(*) for it. So I guess it really is unintentionally.
Savegame compatibility would be broken, obviously.
* Only perhaps, that in this configuration, a two track line without space in between aims right for the center of a upcoming circle. With the fix, a single track may be centered towards the circle, two tracks without space would always be off, as one track will be centered, the other not.
Edit: Changed the subject. "Simple fix for flawed rail geometry" seems to have caused some misunderstandings.
Last edited by tobsimon on Fri May 08, 2015 2:06 pm, edited 1 time in total.
Re: Simple fix for flawed rail geometry
Your proposal is flawed too, though not as badly.
Current situation
Straight radius*: 11
Diagonal radius: 7.5 sqrt(2) = 10.6066
Error: 3.6%
tobsimon's proposal
Straight radius: 10
Diagonal radius: 7 sqrt(2) = 9.8995
Error: 1.0%
If we only did the diagonal change, but kept the straight rails aligned to the 2x2 grid, it would end up in between.
DaveMcW's proposal
Straight radius: 11
Diagonal radius: 8 sqrt(2) = 11.3137
Error: 2.9%
I suspect the developers did it this way because even 1% error is too much. They want an exact calculation of the train's location on a curved track using simple trigonometric functions. If you could provide the code for an efficient function that converts distance along an almost-curved track into smooth x-y coordinates, they might be more interested.
*I measure the radius from the center of the circle to the center of the track.
Current situation
Straight radius*: 11
Diagonal radius: 7.5 sqrt(2) = 10.6066
Error: 3.6%
tobsimon's proposal
Straight radius: 10
Diagonal radius: 7 sqrt(2) = 9.8995
Error: 1.0%
If we only did the diagonal change, but kept the straight rails aligned to the 2x2 grid, it would end up in between.
DaveMcW's proposal
Straight radius: 11
Diagonal radius: 8 sqrt(2) = 11.3137
Error: 2.9%
I suspect the developers did it this way because even 1% error is too much. They want an exact calculation of the train's location on a curved track using simple trigonometric functions. If you could provide the code for an efficient function that converts distance along an almost-curved track into smooth x-y coordinates, they might be more interested.
*I measure the radius from the center of the circle to the center of the track.
Re: Simple fix for flawed rail geometry
You can use bezier curves or (in case of more complex shapes) b-splines. These are very well understood and easy to compute fast. Also, you can just tabularize values for any curve you'd want to use.
Re: Simple fix for flawed rail geometry
The fix actually does keep the straights aligned to the 2x2 grid, just in a different fashion.DaveMcW wrote:[...]kept the straight rails aligned to the 2x2 grid[...]
Aligning a circle to a square grid always is imperfect. That's in the nature of things - also known as the irrationality of sqrt(2).DaveMcW wrote:Your proposal is flawed too, though not as badly.
A radius of 11 and a non-skewed circle would position the starting point of the diagonal at ( 7.78, 7.78 ) which rounds very badly to fit the grid. The radii 7, 10, 17, 24 for example fit much more nicely. Radius 12 fits exceptionally good to ( 8.5, 8.5 ) - relative error 0.1%, but that would need a different positioning of the diagonals.
As psorek said, distance_along_curve calculations are of no concern. Internally the curve is not a circle segment, but a bezièr curve as they are really easy to compute.
Last edited by tobsimon on Fri May 08, 2015 1:33 pm, edited 1 time in total.
Re: Simple fix for flawed rail geometry
Just add a short straight segment to the curve to get rid of the error while providing the correct tangency at the start and finish. You could even distribute the straight length to the start and finish (0.14 tiles each end).
As for the diagonals, I don't see how to get around needing them and providing rail connections at the 45 deg edges.Re: Simple fix for flawed rail geometry
Sure, you could do that, and it would be fine for one curve. But if you want to build two or three in succession, you might prefer a solution that comes together as a good looking circle without too big eye-catching straight segments. That is why you search for a radius, where the 45° angle matches well with the grid. The used 10 tile radius provides that.
Also this is not the kind of error I am concerned with at all.(*) I want to get rid of the straight diagonal piece needed beween two curve segments. These are solely due to the (flawed) placement restriction, which allows a piece of rail only every second tile. But a slight modification of this restriction, as I pointed out, rectifies the problem.
You seem to have used a CAD software for the mockup. In computer graphics you would simply convert the circle to a bezièr curve and drag the endpoints to the places where you want them. Looks good enough like a circle, isn't one anymore, but that's irrelevant.
My personal goal is to come up with a system that also supports a ~22,5° angle well. I'm not quite there yet.
* I will change the topic to no longer read "geometry"
Also this is not the kind of error I am concerned with at all.(*) I want to get rid of the straight diagonal piece needed beween two curve segments. These are solely due to the (flawed) placement restriction, which allows a piece of rail only every second tile. But a slight modification of this restriction, as I pointed out, rectifies the problem.
You seem to have used a CAD software for the mockup. In computer graphics you would simply convert the circle to a bezièr curve and drag the endpoints to the places where you want them. Looks good enough like a circle, isn't one anymore, but that's irrelevant.
My personal goal is to come up with a system that also supports a ~22,5° angle well. I'm not quite there yet.
* I will change the topic to no longer read "geometry"
Re: Simple fix for the ugly rail circles
OK, this is the geometry to get close to matching while fitting within the "box." It is definitely a gentler curve.
As for getting rid of the corner piece (shown overlapping in picture), I suggest providing a sprite image to auto fill that corner based on the connecting geometry. Dead end, 45 deg straight, counter-curve, continued curve and combos. I don't think the "raster" positions need to be changed this way.Re: Simple fix for the ugly rail circles
Every circle segment fills one half of that corner piece (split diagonally). They already do so now.
Other than that, precisely what I had in mind.
Other than that, precisely what I had in mind.
Re: Simple fix for the ugly rail circles
here's what I get with a 22 1/2 deg segment. I'd hate to handle all the different segment variations so a better placement technique would be required. Maybe even have the game determine what type of segment to use based on pathing and get rid of the two types of rails altogether. Could definitely make a compact railyard. Would probably want to integrate the rail signals with the track though. Except for the curves, I think we are still on the raster.
- Attachments
-
- 16 SEGMENT RAIL CIRCLE.gif (31.36 KiB) Viewed 10350 times
Re: Simple fix for the ugly rail circles
I find this so interesting, that I link it to the suggestions board, even knowing, that this is not really a suggestion.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Re: Simple fix for the ugly rail circles
I'm not sure, if I like the move to ideas and suggestions, since I really think of this as a bug, that needs to be fixed. And easily so.
I now finished the promised new rail geometry: https://forums.factorio.com/forum/vie ... =6&t=12603
I now finished the promised new rail geometry: https://forums.factorio.com/forum/vie ... =6&t=12603
Re: Simple fix for the ugly rail circles
Make link back to bugs again. Sorry for hassle.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Re: Simple fix for the ugly rail circles
Thanks and no need to apologize.