Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. A = (3,3,1)
  2. B = (15,2,1)
  3. C = (14,18,1)
  4. IA = (235, 53, 1)
  5. IB = (9, 251, 15)
  6. IC = (55, 25, 247)
  7. T = ((7,3,1), (6,3,1))
  8.  
  9. # ==================
  10.  
  11. def sub(x,y):
  12. return (x[0]-y[0], x[1]-y[1], x[2]-y[2])
  13.  
  14. def product(x,y):
  15. return ( x[1]*y[2] - x[2]*y[1],
  16. x[2]*y[0] - x[0]*y[2],
  17. x[0]*y[1] - x[1]*y[0] )
  18.  
  19. def darea(x,y):
  20. return sum(product(x,y))
  21.  
  22. vba = sub(B,A)
  23. vca = sub(C,A)
  24. area = 1.0 * darea(vba,vca)
  25.  
  26. for t in T:
  27. ta = sub(A,t)
  28. tb = sub(B,t)
  29. tc = sub(C,t)
  30. pab = darea(ta,tb) / area
  31. pbc = darea(tb,tc) / area
  32. pca = darea(tc,ta) / area
  33.  
  34. color = []
  35. for i in range(3):
  36. color.append( pbc*IA[i] + pca*IB[i] + pab*IC[i] )
  37. print t, map(lambda x: "%05.2f" % x, color)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement