intersections between rays and 2D square grid

조회 수: 9 (최근 30일)
anto
anto 2023년 1월 5일
댓글: cr 2023년 1월 5일
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