This paper deals with fundamentals of the function of geometrical shapes. Geometrical shapes exerts its function when it interacts with other shapes in proper way. Functions of mechanism, for example, are generated by geometrical shapes of machine elements and their interaction. Systematic approach to such problem, however, has been little done in spite of its importance. In the present paper, affinity between shapes which is one of the fundamental properities to exert the functions is studied. Contact, relative motion and fixing which appear sequentially in the process of accession of two separate shapes is analysed in probabilistic way. The probability of occurrence of each stable state offers a measure of affinity between these two shapes, which is called static affinity. On the other hand, when some exciting force is applied to shapes the transience between fixing states occurs, the process of which is described as a stochastic process. It is revealed that the process is a Markovian process and its stochastic matrix can be a measure of dynamic affinity between two shapes. Such process is analogous to the reaction between chemical substance, hence the affinity between shapes to free energy of chemical reaction. Some discussion is given to the possibility of application of such parameter as affinity to the design of machine parts to improve the assembling process of them.