whats a quick way to test to make sure a point doesnt line along a line?
Basically i’m creating a plane by using 3 points.
I have 2 points and I want to get the third simply by adding vector.forward or vector.right to a known point.
However adding forward will work for example EXCEPT when all 3 points are along the forward axis. In which case the 3rd point will need to be found adding vector.right.
So assuming I have 2 points and the distance between is of course the slope of the line checking to make sure
point A + (A + vector3.forward) does not lay on the line formed by
point A → Point B
1 Answer
1
Remember, a point is merely a vector from origin, so all you should need to do is make sure that the vector you use to make the third point isn’t the same as the vector from point A to point B:
Vector3 a, b;
Vector3 forward, right;
Vector3 slope = (a - b).normalized;
if(slope == forward) {
return right;
}
return forward;
However, due to floating point arithmetic, you probably want to replace the == with the Dot product and an epsilon:
if(Vector3.Dot(slope, forward) < epsilon) {
return right;
}
return forward;
“Epsilon” (afaik) is the fancy word people use to mean “close enough to call it equal” when dealing with floating point arithmetic - basically, think of it as the allowable error. I’m talking out of my ass here, but I’d think something like 0.1 would work - basically saying, “If slope and forward are within 10% of being the same…”
Anyway - The concepts you want are “dot product”, “cross product” and “normalized”. Normalized is the direction of the vector, dot product is something like the similarity between two vectors, and cross product is a way to make a vector that points away from things. This is all multivariable mathematics / vector calculus / matrix mathematics, and I recommend a Wikipedia or Kahn Academy crawl to learn it, because it’s cool useful stuff.
PS - Sorry I can’t test this code right now, so yell at me if it doesn’t work and I’ll spend some more time on it when I can.
yea I was thinking I THINK what is on here. Basically I can take Point A and Point B do Point A + vector3.forward and then if normalized direction between A -> A vector3.forward == normalized A -> B Then they both have the same slope and so lie on the same line. in that case just A,B, A + vector3.right for my three vecotrs that about right?
– sparkzbarcaYes, although the normalized "A -> A vector3.forward" is the normalized vector3.forward. Think about it.
– originalNarfyep i realized that after i coded it up some. :P
– sparkzbarca