How to convert Parametric equation to Cartesian form - vector

I need to convert a plane's equation from Parametric form to Cartesian form.
For example:
(1, 2, -1) + s(1, -2, 3) + t(1, 2, 3)
to:
ax+yb+cz+d=0
So basically, my question is: how do I find the a, b, c and d, and what's the logic behind the conversion.

Calculate normal vector to this plane :
N = s x t (vector product of two vectors belonging to plane)
Now you have coefficients a, b, c:
N = (a, b, c)
then substitute base point (in general - any point in the plane)
(1, 2, -1) to equation ax+yb+cz+d=0
a+2b-c+d=0
and find d

Related

How to find a point in 3-D at an arbitrary perpendicular line given distance to the point

I have a line AB. I would like to draw a line BC, perpendicular to AB. I know xyz of the points A and B, I also know the distance N between B and C. How can I find an arbitrary point C which fits into the given parameters? The calculations should be done in 3-D. Any point, perpendicular to AB can be the point C, if its distance to B equals N.
An almost identical question is given here, but I would like to know how the same thing is done in 3-D: How do you find a point at a given perpendicular distance from a line?
The calculation that works for me in 2-D was given in the link above:
dx = A.x-B.x
dy = A.y-B.y
dist = sqrt(dx*dx + dy*dy)
dx /= dist
dy /= dist
C.x = B.x + N*dy
C.y = B.y - N*dx
I tried adding Z axis to it like this:
dz = A.z - B.z
dist = sqrt(dx*dx + dy*dy + dz*dz)
dz /=dist
C.z = .... at this point it becomes a mystery to me
If I put something like "C.z - N*dz" into C.z, the distance is accurate only in some rotation angles, I would like to know the correct solution. I can imagine that in 3-D it is calculated in a completely different manner.
Clarification
Point C is not unique. It can be any point on a circle with its
centre at B and radius N. The circle is perpendicular to AB
If the desired point C can be any of the infinitely-many points fitting your requirements, here is one method.
Choose any vector that is not parallel or anti-parallel to vector AB. You could try the vector (1, 0, 0), and if that is parallel you could use (0, 1, 0) instead. Then take the cross-product of vector AB and the chosen vector. That cross-product is perpendicular to vector AB. Divide that cross-product by its length then multiply by the desired length N. Finally extend that vector from point B to find your desired point C.
Here is code in Python 3 that follows that algorithm. This code is somewhat non-pythonic to make it easier to convert to other languages. (If I really did this for myself I would use the numpy module to avoid coordinates completely and shorten this code.) But it does treat the points as tuples of 3 values: many languages will require you to handle each coordinate separately. Any real-life code would need to check for "near zero" rather than "zero" and to check that the sqrt calculation does not result in zero. I'll leave those additional steps to you. Ask if you have more questions.
from math import sqrt
def pt_at_given_distance_from_line_segment_and_endpoint(a, b, dist):
"""Return a point c such that line segment bc is perpendicular to
line segment ab and segment bc has length dist.
a and b are tuples of length 3, dist is a positive float.
"""
vec_ab = (b[0]-a[0], b[1]-a[1], b[2]-a[2])
# Find a vector not parallel or antiparallel to vector ab
if vec_ab[1] != 0 or vec_ab[2] != 0:
vec = (1, 0, 0)
else:
vec = (0, 1, 0)
# Find the cross product of the vectors
cross = (vec_ab[1] * vec[2] - vec_ab[2] * vec[1],
vec_ab[2] * vec[0] - vec_ab[0] * vec[2],
vec_ab[0] * vec[1] - vec_ab[1] * vec[0])
# Find the vector in the same direction with length dist
factor = dist / sqrt(cross[0]**2 + cross[1]**2 + cross[2]**2)
newvec = (factor * cross[0], factor * cross[1], factor * cross[2])
# Find point c such that vector bc is that vector
c = (b[0] + newvec[0], b[1] + newvec[1], b[2] + newvec[2])
# Done!
return c
The resulting output from the command
print(pt_at_given_distance_from_line_segment_and_endpoint((1, 2, 3), (4, 5, 6), 2))
is
(4.0, 6.414213562373095, 4.585786437626905)

Angle between plane normal in different coordinates

I have three vectors a, b, c in cartesian coordinate system x, y, z. Vectors are expressed in 3*3 matrix form by their components on x, y, z coordinates.
Virtual cube is created from vectors a, b, c which starts at same point.
I want to calculate angle between a vector in x,y,z coordinate and a plane inside virtual cube.
Angle between line and plane is found if plane normal is known. But I can't get normal of plane inside a cube.
If you mean the plane that contains a, b, and c, then the plane's normal can be calculated with the cross product:
n = (b - a) x (c - a)
You may want to normalize this vector afterwards. Make sure that your angle calculation is orientation-invariant, i.e. take the absolute value of the dot product.
angle = acos(abs(dot(v, n)) / (norm(n) * norm(v))

How to locate a point in z axis given surface location x,y and z and the distance from the first point?

I have location of a point P1 in x, y and z form. I want to find another point which is directly below this point (in z axis) at a distance d. This means that x & y co ordinates of P2 will be the same as that of P1. How to find the coordinates of P2 (z value)?
Maybe the most correct way would be to define a vector for the original point and one for the difference to the other point. Let a, b, c, represent the x, y, z coordinates for the known point and d is the distance of point 2 below point 1, then something like
v1 = {a, b, c}
diff = {0, 0, d}
and then subtract the two
v2 = v1 - diff
However, to merely get the coordinates of course all you really need to do is to define
v2 = {a, b, c-d}

Finding a line making an angle θ with a known line

I have a line from (a, b) to (x, y), and I would like to draw a line starting at (x, y), with length ℓ, that makes an angle of θ with the original line.
How do I compute the coordinates of the endpoint of this new line? See the diagram:
It's nearly always simpler to use vector algebra for this kind of thing, rather than Cartesian coordinates. Let's start by labelling the points:
Let R(θ) be the matrix that rotates by θ radians counter-clockwise:
Then compute:
v = B − A (the vector from A to B)
v̂ = v / |v| (the unit vector in the direction of v)
ŵ = R(−θ) v̂ (the unit vector in the direction of BC; your rotation is clockwise, so we need R(−θ) here, not R(θ))
w = ℓ ŵ (the vector of length ℓ in the direction of BC)
C = B + w
This approach avoids the need to compute an arctangent, which would need some care (if done naïvely, it runs into trouble when B is vertically above or below A; but most languages have a function like atan2 for handling this case).
In any sensible programming language with a vector library you should be able to write this as a one-liner, perhaps like this:
C = B + (B - A).unit().rotate(-theta) * l
OK, so after a lot of scribbling, I came up with this:
The dashed lines represent lines parallel to the x- and y-axes.
m = x − a
n = y − b
α = tan−1 (n / m)
β = α − θ
p = ℓ cos β
q = ℓ sin β
c = x + p
d = y + q

Bisector of two vectors in 2D (may be collinear)

How to find a bisecor b = (bx, by) of two vectors in general (we consider two non–zero vectors u = (ux, uy), v = (vx, vy), that may be collinear ).
For non-collinear vector we can write:
bx = ux/|u| + vx / |v|
by = uy/|u| + vy / |v|
But for collinear vectors
bx = by = 0.
Example:
u = (0 , 1)
v = (0, -1)
b = (0, 0)
A general and uniform approach is to get the angle of both vectors
theta_u = math.atan2(ux, uy)
theta_v = math.atan2(vx, vy)
and to create a new vector with the average angle:
middle_theta = (theta_u+theta_v)/2
(bx, by) = (cos(middle_theta), sin(middle_theta))
This way, you avoid the pitfall that you observed with opposite vectors.
PS: Note that there is an ambiguity in what the "bisector" vector is: there are generally two bisector vectors (typically one for the smaller angle and one for the larger angle). If you want the bisector vector inside the smaller angle, then your original formula is quite good; you may handle separately the special case that you observed for instance by taking a vector orthogonal to any of the two input vectors (-uy/|u|, ux/|u|) if your formula yields the null vector.
To find the unit bisection vectors of u and v.
if u/|u|+v/|v| !=0
first calculate the unit vector of u and v
then use the parallelogram rule to get the bisection (just add them)
since they both have unit of 1, their sum is the bisector vector
then calculate the unit vector of the calculated vector.
else (if u/|u|+v/|v| ==0):
(if you use the method above, it's like a indintermination: 0*infinity=?)
if you want the bisector of (u0v) if u/|u| = (cos(t),sin(t))
take b=(cost(t+Pi/2),sin(t+Pi/2)) = (-sin(t),cos(t) )as the bisector
therefore if u/|u|=(a1,a2) chose b=(-a2,a1)
Example:
u=(0,1)
v=(0,-1)
the bisector of (u0v):
b=(-1,0)

Resources