intersections between rays and 2D square grid

6 次查看(过去 30 天)
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.

回答(1 个)

cr
cr 2023-1-5
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 个评论
anto
anto 2023-1-5
Ok, so I will work on a code that calculates the equations of straight lines, distinguishes when they are vertical, horizontal or oblique and does the system of equations with every one of the vertical grid lines and horizontal grid lines.
And for storing and ordering the interceptions? Do you have any ideas? for example we could call the grid boxes like this, and assign every intersection to its cell
cr
cr 2023-1-5
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Hypothesis Tests 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by