comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Point of intersection
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Point of intersection [message #61801 is a reply to message #61800] Thu, 31 July 2008 01:51 Go to previous messageGo to previous message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Wed, 30 Jul 2008 08:46:30 -0700 (PDT), kishore1818@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
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Spawn
Next Topic: PSF Energy inside circle

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 03:53:48 PDT 2025

Total time taken to generate the page: 0.16152 seconds