intersections between rays and 2D square grid
조회 수: 9 (최근 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.
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Hypothesis Tests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!