intersections between rays and 2D square grid
7 views (last 30 days)
Show older comments
I'd like to calculate the intersections between a square grid and lines for a problem which looks like this:
Let's say we have 1 point for each side of the square in which the line arrives and starts. Those lines are in black in the figure below.
Let's say also that we have a square grid 3x3 with its cells are represented in red in the figure below.
So far I've coded the positions of the points of start and finish of the lines, so I got a Nx2 matrix, 'start' which represents the coordinates x,y of every starting point, and another Nx2 matrix which has all the corresponding finishing coordinates, 'finish'.
My problem requires calculating those intersections, and storing/ordering them so i can use those intersections in a system of equations.
Does anybody have any ideas on how to do this?
Any help would be greatly appreciated.
0 Comments
Answers (1)
cr
on 5 Jan 2023
Each line has an equation, and in this case several lines have simple equations like y=c (horizontal lines) or x=c (vertical lines)
For lines forming sides of square use eqn for line passing through two points (if not sure just do web search). With 4 of these equations (1 for each side) and the eqns of other lines (horizontals and verticals) simple substitution would yield XY intersection points.
e.g. eqn of bottom left side is y = 0.5-x. This intersects left vertical (line eqn x=.33) at (.33,0.5-0.33) = (.33,0.17).
Henceforth.
2 Comments
cr
on 5 Jan 2023
Not sure if I understood your concern, but you can store intersections xy coordinates in separate variables, say x,y. I suggest you account with lines rather than spaces between them.
See Also
Categories
Find more on Hypothesis Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!