From: "Kenneth Galea" <>
Newsgroups: comp.soft-sys.matlab
Subject: Plot a line perpendicuar to another line from its midpoint
Date: Sat, 3 Apr 2010 19:17:24 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 24
Message-ID: <hp8483$igb$>
Reply-To: "Kenneth Galea" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1270322244 18955 (3 Apr 2010 19:17:24 GMT)
NNTP-Posting-Date: Sat, 3 Apr 2010 19:17:24 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2146944
Xref: comp.soft-sys.matlab:623195

Hi everyone. I'm trying to plot a line perpendicular and in the middle of  another line. I'm already half way through but I'm stuck when trying to plot from the middle: 
check this link: 

I did the following code:

    x1 =GR_endpoints(plotnext,2)  %start point of line
    y1 =GR_endpoints(plotnext,1)  
    x2 =GR_endpoints(plotnext+1,2)  %end point of line
    y2 =GR_endpoints(plotnext+1,1) 
    P1 = [x1 y1]
    P2 = [x2 y2]
    d = 75
    t = sqrt((x2-x1)^2+(y2-y1)^2);
    x3 = x1-(y2-y1)/t*d
    y3 = y1+(x2-x1)/t*d
    line([x3  x1], [y3  y1] , 'Color','b', 'LineStyle','-', 'LineWidth', 0.5)  

N.B. I did not use gradient since I saw one example in this forum but this can lead to a division by 0. Please help