Advertisement
shubhamgoyal

Untitled

Jul 15th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 2.10 KB | None | 0 0
  1. get_random_obj_cord_wrt_mirror(O,M,Tx,Ty,Bx,By, ObjectPlacement) :-
  2.  
  3.         mirror_type(M, MirrorType),
  4.         MirrorType \== plane,
  5.  
  6. %% TODO check that new object does not overlap with existing object if it exists
  7.  
  8.         (retract(eqn_surface(M,Type,G,F,C,Pole_x, Pole_y)) -> assert(eqn_surface(M,Type,G,F,C,Pole_x, Pole_y)); read(_),false),
  9.         (retract(surface(M,Surface_type,Surface_shape,Focal_length)) -> assert(surface(M,Surface_type,Surface_shape,Focal_length)); read(_),false),
  10.        
  11.         Centre_x is -G,
  12.         Centre_y is -F,
  13.         Radius is sqrt(G*G + F*F - C),
  14.         T1 is round(Centre_x + (Radius/sqrt(2))),
  15.         T2 is round(Centre_x - (Radius/sqrt(2))),
  16.         T3 is round(Centre_y + (Radius/sqrt(2))),
  17.         T4 is round(Centre_y - (Radius/sqrt(2))),
  18.  
  19.         nl,write(T1),
  20.         nl,
  21.         write(T2),
  22.         nl,
  23.         write(T3),
  24.         nl,
  25.         write(T4),nl,
  26.         %% front means object is on the left
  27.         %% back means object is on the right
  28.         (Surface_type == mirror ->
  29.             (Surface_shape == concave ->
  30.                 (
  31.                     ObjectPlacement == front ->
  32.                         (
  33.                             Centre_x > Pole_x ->
  34.                                 random_between(round(Pole_x - 2 * Radius), round(Pole_x - 1), Tx),
  35.                                 random_between(T4, T3, Ty);
  36.  
  37.                                 random_between(T2, T1, Tx),
  38.                                 random_between(T4, T3, Ty)
  39.                         );
  40.  
  41.                         (
  42.                             Centre_x > Pole_x ->
  43.                                 random_between(T2, T1, Tx),
  44.                                 random_between(T4, T3, Ty);
  45.  
  46.                                 random_between(round(Pole_x + 1), round(Pole_x + 2 * Radius), Tx),
  47.                                 random_between(T4, T3, Ty)
  48.                         )
  49.                 );
  50.  
  51.                 %% Convex Mirror
  52.                 (
  53.                     ObjectPlacement == front ->
  54.                         (
  55.                             Centre_x > Pole_x ->
  56.                                 random_between(round(Pole_x - 2 * Radius), round(Pole_x - 1), Tx),
  57.                                 random_between(T4, T3, Ty);
  58.  
  59.                                 random_between(round(Pole_x + 1), round(Pole_x + 2 * Radius), Tx),
  60.                                 random_between(T4, T3, Ty)
  61.                         );
  62.  
  63.                         random_between(T2, T1, Tx),
  64.                         random_between(T4, T3, Ty)
  65.                 )
  66.             );
  67.  
  68.             %% TODO We have only taken one side of lens, take two sides
  69.             random_between(T2, T1, Tx),
  70.             random_between(T4, T3, Ty)
  71.         ),
  72.  
  73.         nl,write('error here'),nl,read(_),
  74.  
  75.         get_bottom_cord_from_top_cords(T1,T2,T3,T4, Tx, Ty, Bx, By).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement