From: Kenneth Galea on 3 Apr 2010 15:17 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
From: Roger Stafford on 3 Apr 2010 17:44 "Kenneth Galea" <k.galea(a)hotmail.com> wrote in message <hp8483$igb$1(a)fred.mathworks.com>... > 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: > ........ > 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) > ....... You are using the wrong base point. For the midpoint use this: t = sqrt((x2-x1)^2+(y2-y1)^2); x0 = (x1+x2)/2; y0 = (y1+y2)/2; x3 = x0-(y2-y1)/t*d; y3 = y0+(x2-x1)/t*d; line([x3 x0], [y3 y0] , ..... Roger Stafford
|
Pages: 1 Prev: SPECT Projection Reconstruction & Sinograms Next: opening text file using gui pushbutton |