/* rules.
Inference rules for Roller Coaster problems
Alan Bundy 7.4.81 */

/* Path is free of particle to travel on, 
i.e. no friction or extraneous forces */

  free(Path,Part,Per)
	:- forall( ncc(fixed_contact(Part,Point,Per)), dc point_of(path,Path,Point) ),
	   ncc coeff(Path,zero),
	   thnot(force(Part,F,Dir,Per)).

/* This is a motion type problem */

  probtype(motion)
	:- ncc probtype(roller_coaster) ;
	   ncc probtype(motion_in_a_straight_line).



/* Default: paths in motion problems are frictionless */
  coeff(Path,zero)
	:- type(path,Path),
	   ncc probtype(motion).

/* The friction of paths is inherited by their subpaths */
  coeff(Path,Mu)
	:- bitof(Path,Suppath),
	   ncc coeff(Suppath,Mu).


/* Default: a path is assumed rough if it is not known to be smooth */
  rough(Path) :- thnot( ncc(coeff(Path,zero)) ).



/*VERTICAL DROP OF PATH FROM START TO FINISH*/
/*------------------------------------------*/

/* drop of horizontal straight line is zero */
drop(Start,Finish,zero) :-
	farend(Path,Start,Finish),
	dc concavity(Path,stline),
	horizontal(Path,Start).

/* drop of straight line can be calculated from ground */
drop(Start,Finish,-(D*tan(Ang))) :-
    farend(Path,Start,Finish),
    dc concavity(Path,stline),
    ncc incline(Path,Ang,Start), dc ground(Path,D).

/* drop is anti-commutative */
/* drop(Start,Finish,-H) :-
	ncc drop(Finish,Start,H).
*/
/* drop of path is sum of drops of subpath */
drop(Start,Finish,Hsum) :-
	farend(Path,Start,Finish),
	dc partition(Path,Pl),
	sumdrops(Pl,Start,Hsum).


/*VERTICAL DROP OF CIRCLE SEGMENT*/
drop(Start,Finish,R*(sin(Dir1)-sin(Dir2))) :-
  dc point_of(_,Path,Start),
  dc point_of(_,Path,Finish),
  partof(Path,Circle),
  dc circle(Circle),
  ncc angle(Circle,Dir1,Start),
  ncc angle(Circle,Dir2,Finish),
  ncc radius(Circle,R).

/* Sum of Drops across partition */
sumdrops([],Start,0).

sumdrops([P|Pl],Start,H+Sum) :-
    farend(P,Start,Finish),
    ncc drop(Start,Finish,H), !, 
    sumdrops(Pl,Finish,Sum).

/*RADIUS OF CURVATURE OF CIRCLE SEGMENT*/
radius(Path,R) :-
  partof(Path,Circle), dc circle(Circle),
  cc radius(Circle,R).

