フィルターのクリア

Function that plots and calculates intersection of lines

2 ビュー (過去 30 日間)
SOFOKLIS SOFOKLEOUS
SOFOKLIS SOFOKLEOUS 2019 年 11 月 29 日
編集済み: Dhananjay Kumar 2019 年 12 月 3 日
I have to create a function that gets a matrix as an input that represent lines and each row contains 4 numbers (x1 y1 x2 y2).
The function has to plot the lines, calculate and mark the intersection point of the lines.
The function starts like this:
function [LL] = intersects(lines)
%plot and calculate lines and intesection
LL = [ ]; %Contains the intersection point
  2 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 11 月 29 日
This seems like homework so please show what you have tried so far. You will (probably) need to determine the equation for each line and then solve for the intersection for each pair of lines.
SOFOKLIS SOFOKLEOUS
SOFOKLIS SOFOKLEOUS 2019 年 11 月 29 日
編集済み: SOFOKLIS SOFOKLEOUS 2019 年 11 月 29 日
I can plot and find the intersection points of lines out of a function. However this exercise requires that the input is in the form of a matrix. Normally I can manipulate the values by assigning them as x1 y1 x2 y2 but in the above function the matrix is enteres as 'lines' so I can no longer use each value separately.

サインインしてコメントする。

回答 (1 件)

Dhananjay Kumar
Dhananjay Kumar 2019 年 12 月 3 日
編集済み: Dhananjay Kumar 2019 年 12 月 3 日
You can do it manually through basic mathematical principles.
y-y1 = m(x-x1) => mx-y = mx1-y1 . Now this is in the form of ax+by = c.
(Here m = (y2-y1)/(x2-x1) )
Make another matrix A and a column vector b from the given input matrix.
Each row of A is [m ,-1] and corresponding element in b would be mx1-y1.
Now loop through each row and find the intersection points with all the other rows(which is not current row) inside another loop. (To solve for a pair of rows make 2x2 matrix A_temp and a 2x1 b_temp matrix and use mldivide ) Keep putting those intersection points in a matrix. Return the matrix

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by