#--------Python module for OEIS sequence number A092866.------ #------------------------------------------------------------------- # Example of use # >>>> A092866(6) # 1237 #------------------------------------------------------------------- #Three points are collinear if the determinant of the matrix of their barycentric coordinates vanishes def A092866_coef_matrice(a1,b1,c1,a2,b2,c2): k1=b1*c2-b2*c1 k2=a2*c1-a1*c2 k3=a1*b2-a2*b1 return k1,k2,k3 class A092866_InternalPoint(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) def A092866_Internal(x): if (x[0]<=0 or x[1]<=0 or x[2]<=0 or x[0]>=1 or x[1]>=1 or x[2]>=1): raise A092866_InternalPoint("Not inside the triangle") #Finding the intersection coordinates between two lines def A092866_interLines(l1,l2): a=A092866_coef_matrice(l1[0][0],l1[0][1],l1[0][2],l1[1][0],l1[1][1],l1[1][2]) b=A092866_coef_matrice(l2[0][0],l2[0][1],l2[0][2],l2[1][0],l2[1][1],l2[1][2]) m=matrix([[a[0],a[1],a[2]],[b[0],b[1],b[2]],[1,1,1]]) y = vector([0,0,1]) try: g=m.solve_right(y) A092866_Internal(g) except (ValueError, A092866_InternalPoint): return None else: return tuple(g) def A092866_points_lines(n): # collection of points x=[1,0,0] y=[0,1,0] z=[0,0,1] x1=[((x[0]+y[0])*(i/n),(x[1]+y[1])*((n-i)/n),0) for i in range(1,n)] y1=[(0,(z[1]+y[1])*(i/n),(z[2]+y[2])*((n-i)/n)) for i in range(1,n)] z1=[((z[0]+x[0])*(i/n),0,(z[2]+x[2])*((n-i)/n)) for i in range(1,n)] a=[(tuple(x), tuple(y1[k])) for k in range(n-1)] b=[(tuple(y), tuple(z1[k])) for k in range(n-1)] c=[(tuple(z), tuple(x1[k])) for k in range(n-1)] d=[((x1[k]),(y1[l])) for k in range(n-1) for l in range(n-1)] e=[((x1[k]),(z1[l])) for k in range(n-1) for l in range(n-1)] f=[((z1[k]),(y1[l])) for k in range(n-1) for l in range(n-1)] g=[(tuple(x), tuple(y))] h=[(tuple(y), tuple(z))] i=[(tuple(z), tuple(x))] # Construction of lines L=(a+b+c+d+e+f+g+h+i) return L def A092866(n): L=A092866_points_lines(n) #Finding intersections q=[A092866_interLines((L[p]),L[j]) for p in range(len(L)) for j in range(p+1,len(L)) if p!=j] #Each intersection has to be calculated once time f=set(q) f.remove(None) intersection=len(f) return intersection