I've done something similar in maxscript before to figure out a 3D point in 
space based on 2D screen positions (from a known camera).... its basically the 
same as points to 3D in Nuke but works of 2 screen positions

I dont know how to sort you out in Nuke but below is the maxscript function I 
made which you should be able to read like pseudo code. I've bolded the 
important formula bit. I found the formula super confusing when I first looked 
at but managed to hack it all together

basic outline is to convert each cameras pos and rot to a single vector 
describing its direction (mine was a direction a 3d point yours will be able to 
be derived from the cmaera matrix as a single vector (my matrix math is rusty 
so I cant recall exactly how atm) some clever person here can hopefully fill in 
that blank

The actually formula I just grabbed of the net to derive the closest point 
between 2 vectors. It gives a point on each vector which I then subtract from 
each other and divide by 2 to get the mid point between them.

Hope this helps

fn dothesolve thetracker thecamera=
(

 -- get vectors from keys into array
 global vectarray = #()
 global camarray = #()
 if thetracker.position.controller.keys.count > 1 then
 (
  for i in thetracker.position.controller.keys do
  (
   --print i.time
   thepos = at time i.time thetracker.position
   --print thepos
   thevector = at time i.time ( thepos - thecamera.pos )
   --print thevector
   append vectarray thevector
   append camarray (at time i.time (thecamera.pos))
   print camarray
   print vectarray
   print "end"
  )

  -- compare sets of 2 trackers preferably far apart.


  u = vectarray[1]
  v = vectarray[2]
  P = camarray[1]
  Q = camarray[2]
  w = P - Q

  pA = dot u u
  pB = dot u v
  pC = dot v v
  pD = dot u w
  pE = dot v w

  S = (pB*pE - pC*pD)/(pA*pC - pB^2)
  T = (pA*pE - pB*pD)/(pA*pC - pB^2)


  Solvepos1 = P + u * S
  Solvepos2 = Q + v * T



  print "solve"
  print solvepos1
  print solvepos2
  newpoint = point()
  newpoint.pos = (solvepos1 + solvepos2)/2
  print newpoint.pos
  newpoint.wirecolor = (color 134 6 6)
  newpoint.name = uniquename "T_Solve"
 )
 else
 (
  print "you need more than one track key"
 )
)

________________________________
From: [email protected] 
[mailto:[email protected]] On Behalf Of Paul Raeburn
Sent: Thursday, 2 August 2012 9:45 PM
To: [email protected]
Subject: [Nuke-python] calculating stereo camera convergence.

I am trying to work out how to calculate the distance a pair of tracked stero 
cameras converge at.  So I have the position and rotation of both, and need to 
work out the distance their vectors get the closest to intersection and it's 
doing my head in.

Anyone have any pointers on where to start with that one?
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to