How to find points between two intersecting lines? (2024)

4 views (last 30 days)

Show older comments

Niraj Bal Tamang on 22 May 2021

  • Link

    Direct link to this question

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines

  • Link

    Direct link to this question

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines

Commented: Niraj Bal Tamang on 26 May 2021

Accepted Answer: G A

  • usarea vs slope domains.jpg

I have two straight lines defined by equations (say) x+y=3 and 2x-3y=4. I have to find out the points which lies between these two lines in the xy plot as in the attached figure. Can anyone suggest me how can i find the points between two lines in a plot?

Thank You

2 Comments

Show NoneHide None

Image Analyst on 23 May 2021

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1536518

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1536518

Those lines are not on your graph.

Niraj Bal Tamang on 23 May 2021

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1536528

  • H_usarea_and_slope.mat

Sorry. I just gave a random equations of straight line for assumption. I am attaching the whole code and variables if you want to give it a try. I am trying to get the points between each of those lines for classification.

scatter(usarea,slope);

set(gca,'xscale','log','yscale','log');

xlabel('Upstream Drainage Area (sq km)');

ylabel('Slope (m/m)');

hold on

xline(7*10^5,'Color','r','LineStyle','--');%vertical line

hold on

plot([1.1*10^6 10^10],[0.15 0.15],'--r');%horizontal line

hold on

plot([7*10^5 5*10^9],[0.2 10^-4],'--r');%diagonal line

hold off

grid on

Sign in to comment.

Sign in to answer this question.

Accepted Answer

G A on 23 May 2021

  • Link

    Direct link to this answer

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#answer_706173

  • Link

    Direct link to this answer

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#answer_706173

Edited: G A on 23 May 2021

myData = [X,Y];

y1 = 3 - X;

y2 = 2/3*X + 4/3;

Y1 = Y(Y < y2 & Y > y1);

X1 = X(Y < y2 & Y > y1); % or X1 = X(Y == Y1)

myData1 = [X1,Y1];

4 Comments

Show 2 older commentsHide 2 older comments

Niraj Bal Tamang on 26 May 2021

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1542490

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1542490

  • H_usarea_and_slope.mat

Is this applicable for the scatterplot also? I want to define lines in the plot and categorize the points between those lines.

scatter(usarea,slope);

set(gca,'xscale','log','yscale','log');

xlabel('Upstream Drainage Area (sq km)');

ylabel('Slope (m/m)');

hold on

xline(7*10^5,'Color','r','LineStyle','--');%vertical line

hold on

plot([1.1*10^6 10^10],[0.15 0.15],'--r');%horizontal line

hold on

plot([7*10^5 5*10^9],[0.2 10^-4],'--r');%diagonal line

hold off

grid on

G A on 26 May 2021

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1543450

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1543450

It does not matter how are you are plotting your X-Y data. If your data are defined by X and Y arrays of the same length (myData), then you can use the method I have shown to get the data between lines given by [X,y1] and [X,y2]. Those data are defined as myData1=[X1,Y1], again, lengths of X1 and Y1 are equal. And these data ([X,Y] and [X1,Y1] or [X,y1] and [X,y2]) you can plot in any way you wish.

G A on 26 May 2021

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1543645

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1543645

load('H_usarea_and_slope.mat',"usarea","slope")

scatter(usarea,slope);

set(gca,'xscale','log','yscale','log');

xlabel('Upstream Drainage Area (sq km)');

ylabel('Slope (m/m)');

hold on

xline(7*10^5,'Color','r','LineStyle','--');%vertical line

hold on

plot([1.1*10^6 10^10],[0.15 0.15],'--r');%horizontal line

hold on

plot([7*10^5 5*10^9],[0.2 10^-4],'--r');%diagonal line

grid on

X=usarea;

Y=slope;

Y1=ones(size(X))*0.15; % horizontal line

B=1e7; % vertical line, I shifted it to the right for demonstration purpose

% defining diagonal line as log(y)=a*log(x)+b

x1=log(7e5);

x2=log(5e9);

y1=log(0.2);

y2=log(1e-4);

a=(y2-y1)/(x2-x1);

b=y1-a*x1;

Y2=exp(a*log(X)+b); % diagonal line

Y3 = Y(Y < Y1 & Y > Y2 & X > B); % Y-data between lines

X3 = X(Y < Y1 & Y > Y2 & X> B); % X-array

plot(X3,Y3,'.r');

plot(X,Y1,'--b');

plot(X,Y2,'--g');

xline(B,'--m');

hold off

Niraj Bal Tamang on 26 May 2021

Direct link to this comment

https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1544215

  • Link

    Direct link to this comment

    https://www.mathworks.ca/matlabcentral/answers/837143-how-to-find-points-between-two-intersecting-lines#comment_1544215

Thank you so much.It's working now.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D Plots

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

  • matlab

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to find points between two intersecting lines? (9)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

Europe

Asia Pacific

Contact your local office

How to find points between two intersecting lines? (2024)
Top Articles
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 6356

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.