Re: Point of intersection [message #61786] |
Thu, 31 July 2008 06:44  |
kishore1818
Messages: 24 Registered: June 2007
|
Junior Member |
|
|
On Jul 31, 5:51 am, Wox <nom...@hotmail.com> wrote:
> On Wed, 30 Jul 2008 08:46:30 -0700 (PDT), kishore1...@gmail.com wrote:
>> ...how to find out that
>> particular interesection x and y value.
>
> The could below works for any x and y values but might be simplified
> in your case (special y values).
>
> function segmentintersect,L1x,L1y,L2x,L2y,xy=xy
>
> ; code:
> ; 0: no intersecting
> ; 1: intersect in 1 point
> ; 2: parallel
> ; 3: coincident
>
> denom=float(L2y[1]-L2y[0])*(L1x[1]-L1x[0])-(L2x[1]-L2x[0])*( L1y[1]-L1y[0])
> numa=(L2x[1]-L2x[0])*(L1y[0]-L2y[0])-(L2y[1]-L2y[0])*(L1x[0] -L2x[0])
> numb=(L1x[1]-L1x[0])*(L1y[0]-L2y[0])-(L1y[1]-L1y[0])*(L1x[0] -L2x[0])
>
> if denom eq 0 then code= (numa eq 0 and numb eq 0)+2 $
> else begin
> ua = numa / denom
> ub = numb / denom
>
> code= ua ge 0 and ua le 1 and ub ge 0 and ub le 1
> if code then $
> xy=[L1x[0]+ua*(L1x[1]-L1x[0]),L1y[0]+ua*(L1y[1]-L1y[0])]
> endelse
>
> return,code
> end;function segmentintersect
> ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%
>
> pro segtest
>
> x1=[0.1,0.2,0.6,0.7]
> x2=[0.5,0.4,0.5,0.3]
> y1=[1,2,3,4]
> y2=y1
>
> window
> plot,x1,y1,psym=-2
> oplot,x2,y2,psym=-2
>
> n=n_elements(x2)
> y2_1=interpol(y1,x1,x2)
> b=y2_1 gt y2
> interval=where(b[0:n-2]-b[1:*],ct)
> if ct ne 0 then begin
> xy=fltarr(2,ct)
> for i=0,ct-1 do begin
> j=interval[i]
> L2x=x2[j:j+1]
> L2y=y2[j:j+1]
> j=value_locate(x1,L2x)
> k=0
> repeat begin
> L1x=x1[j[k]:j[k]+1]
> L1y=y1[j[k]:j[k]+1]
> code=segmentintersect(L1x,L1y,L2x,L2y,xy=tmp)
> b=code eq 1
> if b then begin
> xy[*,i]=tmp
> plots,[tmp[0],tmp[0]],[0,tmp[1]],/data
> endif
> k++
> endrep until b or (k eq 2)
> endfor
> endif
>
> end;pro segtest
> ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%
Hi,
Thanks for your program. This is useful for multiple intersection of
two lines. It is very interesting.
Kishore
|
|
|