In this exercise, I used a geometrical method for three triangles that connect and make a collapsible pyramid. It works for one triangle and the others are copies of this one.
As you can see, we have a circle, and the center of the circle is one vertex of triangle that will use as center of the pyramid. also, we have a sphere. the intersection of the circle and sphere specifies the amount of movement for vertexes of the triangle.
Although I saw several methods to do this, It works properly and almost was an easy way.
as you know, Its a actually part of Al bahar tower: