Path: news.mathworks.com!not-for-mail
From: "Kenneth Galea" <k.galea@hotmail.com>
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$1@fred.mathworks.com>
Reply-To: "Kenneth Galea" <k.galea@hotmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1270322244 18955 172.30.248.37 (3 Apr 2010 19:17:24 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 3 Apr 2010 19:17:24 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2146944
Xref: news.mathworks.com 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:
 http://dl.dropbox.com/u/5800838/untitled.jpg 

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

Regards
Kenneth