Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
computation between a point and line

Subject: computation between a point and line

From: aiden

Date: 12 Oct, 2010 07:09:06

Message: 1 of 3

Friends,

I have matrix representing Line coordinates (x1 , y1 , x2 , y2) as follows:

lines = [ 62 2 48 15
                       11 9 34 12
                       18 22 10 73 ]

There are 4 Lines where each row is a line.

So from here I'll use the notation as follows:
P ----> Point on Line 1
L ----> Line 2

The formula I'd like to use in the computations is :

(L_y1 - L_y2)*P_x1 + (L_x2 - L_x1)*P_y1

So, for example with respect to Line 1 and Line2 (i.e. row 1 and row 2), substituting numbers into the formula would be:

Point1 in Line1 in relation to Line2 = (9 -12)*62 + (34 - 11)*2

My problem is performing this equation for all Line combinations as:

---- Point1 in Line1 in relation to Line2 -----
---- Point1 in Line1 in relation to Line3 -----

---- Point1 in Line2 in relation to Line1 -----
---- Point1 in Line2 in relation to Line3 -----

---- Point1 in Line3 in relation to Line1 -----
---- Point1 in Line3 in relation to Line2 -----

I am new to Matlab programming and would like ask for some assistance.

Cheers,
aiden

Subject: computation between a point and line

From: aiden

Date: 12 Oct, 2010 07:19:05

Message: 2 of 3

Just to correct , there are 3 Lines.

aiden

Subject: computation between a point and line

From: Grzegorz Knor

Date: 12 Oct, 2010 08:28:06

Message: 3 of 3

"aiden " <aidenjobe@gmail.com> wrote in message <i911ii$e3e$1@fred.mathworks.com>...
> Friends,
>
> I have matrix representing Line coordinates (x1 , y1 , x2 , y2) as follows:
>
> lines = [ 62 2 48 15
> 11 9 34 12
> 18 22 10 73 ]
>
> There are 4 Lines where each row is a line.
>
> So from here I'll use the notation as follows:
> P ----> Point on Line 1
> L ----> Line 2
>
> The formula I'd like to use in the computations is :
>
> (L_y1 - L_y2)*P_x1 + (L_x2 - L_x1)*P_y1
>
> So, for example with respect to Line 1 and Line2 (i.e. row 1 and row 2), substituting numbers into the formula would be:
>
> Point1 in Line1 in relation to Line2 = (9 -12)*62 + (34 - 11)*2
>
> My problem is performing this equation for all Line combinations as:
>
> ---- Point1 in Line1 in relation to Line2 -----
> ---- Point1 in Line1 in relation to Line3 -----
>
> ---- Point1 in Line2 in relation to Line1 -----
> ---- Point1 in Line2 in relation to Line3 -----
>
> ---- Point1 in Line3 in relation to Line1 -----
> ---- Point1 in Line3 in relation to Line2 -----
>
> I am new to Matlab programming and would like ask for some assistance.
>
> Cheers,
> aiden

There is a code:
K = zeros(3);

for k=1:3
    for j=1:3
        K(k,j) = (lines(k,2)-lines(k,4))*lines(j,1) + (lines(k,3)-lines(k,1))*lines(j,2);
    end
end

or without loops:

k = [1 1 1 2 2 2 3 3 3];
j = [1 2 3 1 2 3 1 2 3];

L = (lines(k,2)-lines(k,4)).*lines(j,1) + (lines(k,3)-lines(k,1)).*lines(j,2);

Grzegorz

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us