Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 2.87 KB | None | 0 0
  1. function vertices=radon2vertices(radonpts)
  2.         #converts the radon points in the format offset,angle (from +ive yaxis) to y=ax+b form
  3.         line_cts=[tan((-radonpts(:,2)).*pi/180),radonpts(:,1)./cos(radonpts(:,2).*pi/180)];
  4.         #we now have a set of 4 y=ax+b type line eqations
  5.         #each line should intercept three others, two of the interception points will be vertices of the screen
  6.         #one further interception point will usually be present due to the perspective effects
  7.         #we need to probe the six different possible combinations, giving sixinterception points
  8.         points(1:3,1)=(line_cts(2:4,2).-line_cts(1,2))./(line_cts(1,1).-line_cts(2:4,1));#line one intersections
  9.         points(4:5,1)=(line_cts(3:4,2).-line_cts(2,2))./(line_cts(2,1).-line_cts(3:4,1));#line two intersections
  10.         points(6,1)=(line_cts(4,2).-line_cts(3,2))./(line_cts(3,1).-line_cts(4,1));#lines three and four intersection
  11.         #these are the x co-ordinates of our interception points, now calculate y
  12.         points=[points(1:3,1),points(1:3,1).*line_cts(1,1).+line_cts(1,2);points(4:5,1),points(4:5,1).*line_cts(2,1).+line_cts(2,2);points(6,1),points(6,1)*line_cts(3,1)+line_cts(3,2)];
  13.         #we now have the six intercept points, and 4 line equations, the next stage is to solve for the 4 sided polygon
  14.         #we start by marking each point that has a point either side of it along one of the lines
  15.         pointsmarks=zeros(6,1);#in the consecutive order they were defined
  16.         lookp=[1,2,3;1,4,5;2,4,6;3,5,6];#lookup table for the positions in the pointsmark list
  17.         #now check lines, this is a little bit complex due to the way the line combinations are generated
  18.         for k=1:4       #loop over the three remaining lines
  19.                 [res,order]=sort(points(lookp(k,1:3),1));
  20.                 pointsmarks(lookp(k,order(2)))=1;#mark the middle point
  21.         endfor
  22.         #the points are now marked, we should find that there are three marked points(one has been marked twice)
  23.         #of the non marked points, we eliminate the two on lines that pass through three marked points
  24.         m=1;
  25.         for n=1:6       #loop through the 6 points
  26.                 pointsonlines=0;
  27.                 if pointsmarks(n)==0    #an unmarked point - all the points that need to be removed will be unmarked
  28.                         for k=1:4       #loop over the three remaining lines
  29.                                 if find(n==lookp(k,1:3))
  30.                                         pointsonlines+=sum(pointsmarks(lookp(k,1:3)));
  31.                                 endif
  32.                         endfor
  33.                 endif
  34.                 if(pointsonlines<3)     #if theres are less than 3 marked middle points on the lines connected to the vertex
  35.                         vertices(m,:)=points(n,:);
  36.                         m+=1;
  37.                 endif
  38.         endfor
  39. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement