Tuesday, November 30, 2010

Mel : How to find center of 2 selected vertex


 given 2 vectors cast a point on the line.
so if we know 2 points out  in 3d space and if you want to shoot a point along the line anywhere in 3d space you can achieve this using vector equation of a line.you can also find center of 2 Selected vertex.



using vector equation of line
r = ro + a
a = t*(v)
r = ro + t*(v)

t*(v) will be a vector that lines along the line and it tells us how far from the original point that we should move. if t is positive we move away from the original point in direction of vector v and if t is negative we move away from the original point in the opposite direction of vector v. note vector v can be anywhere in 3D as long as it is parallal to a.

string $verts[] = `ls -sl -fl`;
vector $ro = `pointPosition $verts[0]`;
vector $r = `pointPosition $verts[1]`;
vector $v = $r - $ro;
float $result[] = $ro + (0.5*$v);
$sl = `spaceLocator`;
move $result[0] $result[1] $result[2] $sl;

above script will create a locator in the center of 2 selected vertex as i used t as 0.5 here.

imagine your first point is camera position and second point is 2d pattern looking thru camera. if you want to extend the ray from these 2 points far enough you can use above script with the t value whatever you like. you can go t over 1 so the third point goes beyond your second point.

No comments:

Integration/Tracking Demo Reel 2018 on Youtube