rel="stylesheet" href="https://cloudflare.com">
Showing posts with label line. Show all posts
Showing posts with label line. Show all posts

Monday, December 6, 2010

Intersection between Line and the Plane




A and B are the 2 known points on the line and t is the parameter which will allow us to find a point P on the line.
lets assume that P is the point of intersection between a line and a plane
in order to find point P we will need to find value of the parameter t.
to find t, we plug equation of line into the equation of plane, where we have everything we need to calculate t.
once we have t, we plug into our equation of line back to find P.

The equation of a line is:
P = A + t(B – A)                 ------------------------------------------------------------------  (1)

- P  is any arbitrary point on the line.  In this case, P is the point of intersection of the ray and the plane
- A is the starting point of the line
- B is the end point of our line segment
- t is the parameter.  Values between 0 and 1 represent points on our line.
- Po and Co are position vector for P and C.
- Po-Co will lie completely in the plane. hence dot product of this to planes normal will be zero.


The equation of a plane is:
N dot (P – C) = 0                ------------------------------------------------------------------  (2)
- N is the normal of the plane
- P and C are known points on the plane.  In this case, P will represent the point of intersection. If our plane was represented by a triangle, C could be one of the vertices.

Plug the equation of the ray from ---(1) into our intersection pt of the equation of the plane ---(2).

N dot ( (A + tV) – C) = 0
Solve for t:
(N dot (A + tV)) – (N dot C) = 0
(N dot (A + tV)) = (N dot C)
(N dot A) + (N dot tV) = (N dot C)
N dot tV = (N dot C) - (N dot A)
t = N dot (C – A) /N dot V       ------------------------------------------------------------------  (3)

so we calculated the value of t. we can use this value in the line equation to find the co-ordinates  of the intersection point
we have all the information on the right side of equal sign mean we can find P.
puting t in equation of line
P = A + t(B – A)                 ------------------------------------------------------------------  (4)

If:
t > 0 and t < 1  : The intersection occurs between the two points
t = 0            : The intersection falls on the first point
t = 1            : Intersection falls on the second  point
t > 1            : Intersection occurs beyond second Point
t < 0            : Intersection happens before 1st point.

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.

Integration/Tracking Demo Reel 2023 on Youtube Integration/Tracking Demo Reel 2018 on Youtube