0

I'm using a self made matrix as some kind of map

    def __init__(self, rows = 10, colls = 10):
    self.matrixRC = []
    for _ in range(rows):
        self.matrixRC.append([2 for _ in range(colls)])

and I was wondering if there was an easy way to make a y = ax line function tell me what spaces of my matrix it goes trough (without checking all the points on the line).

An other way to put the problem, how do i know what box of my millimeterpaper my line goes trough (it starts on an intersection of two of my millimeterpaper lines).

p.s. sorry if my explanation isn't to good.

Exmaple:

..........
..##....#.
........#.
..........
..........
..........
..........
ss........
ss........
..........

so here the place where I start looking is the place in-between the 4 's' and I'd like a function/algorithm which tells me if a line at a certain angle (I'm setting 0 at the top so to the right would be 90 or Pi/2 degrees) hits a square with a # and preferably fighter the length of the line at that point of the location of the # both are fine.

Brendan Mesters
  • 203
  • 1
  • 10
  • You should add a couple examples so that it gets clearer. For example, where do you place (0, 0)? In the left-bottom corner? – Adirio Oct 20 '17 at 09:30
  • 1
    Are you looking for [ray-grid traversal](https://www.scratchapixel.com/lessons/advanced-rendering/introduction-acceleration-structure/grid)? – Nico Schertler Oct 20 '17 at 10:29
  • Yeah a ray-grid traveral is the thing I thought i was looking for, tough with further consideration i make the decision to use a different way to find the info I needed. Still thx for the help – Brendan Mesters Oct 20 '17 at 10:47
  • https://stackoverflow.com/questions/35807686/find-cells-in-array-that-are-crossed-by-a-given-line-segment/35810470#35810470 – MBo Oct 20 '17 at 12:22

0 Answers0