pi=3.1415926535897932384626433832795
spineArea=1.2

proc calc_spines() {local aveDiam,radius,spineLength,alpha,corrF,n_points,R,r,side,A_shaft,A_spines,n_n,neuronArea,count,n_spines
	n_spines = 0
	
	if (count_spines != 0) {
		aveDiam = 0.0
		count = 0
		for (n_n) {
			aveDiam += diam(n_n)
			count += 1
		}
		
		aveDiam /= count
		radius = aveDiam/2.0
		spineLength = 1.25
		alpha = my_asin_asin(radius/(radius+spineLength))
		corrF = pi/(pi-2.0*alpha)
		if (debug_mode) printf("\nCorrection factor for hidden spines in section %s: %f\n",secname(),corrF)
		count_spines *= corrF
		if (debug_mode) n_spines += count_spines
	}
	if (debug_mode) printf("Spine density in section %s=%f/um\n",secname(),count_spines/L)
	// get the total area of the spines:
	A_spines=count_spines*spineArea
		
	// get the area of the shaft:
	A_shaft=0.0
	for (n_points=0;n_points<n3d()-1;n_points+=1) {
	// get the surface area of a truncated cone
	// between neighbouring points:
		height=arc3d(n_points+1)-arc3d(n_points)
		R=diam3d(n_points+1)/2.0
		r=diam3d(n_points)/2.0
		side = sqrt((R-r)*(R-r)+height*height)
		A_shaft+=pi*side*(R+r)
	}
	scale_spines=(A_shaft+A_spines)/A_shaft
	if (debug_mode) {
		neuronArea=0.0
		for (n_n) {
			neuronArea+=area(n_n)
		}
	}
}