0
\$\begingroup\$

I am trying to walk a line that is intersecting a mesh, and given the point on the line I need to see what vertices may be perpendicular to it. My initial idea was to attempt a dot product between the line's direction vector and the direction vector from the point on the line to the mesh's vertex, and then only accept values that were near 0. This resulted in a collection of vertices behind the point on my line. Playing with the threshold values for the dot product check do not seem to help either. Any ideas?

Code

//actual_pos = position of the vertex
//trav_in_soace = point along the line
//m_fireDir = normalized direction vector of the line

Vector3 dir_to_point = actual_pos - trav_in_space;
dir_to_point.Normalize();

float dot_accept = DotProduct(m_fireDir, dir_to_point);
if (dot_accept > max_threshold || dot_accept < min_threshold)
    continue;

Picture with threshold values near 0.5

This is best result I can get and it is still really inaccurate. The orange verts are the points on the purple line, the red and blue are what should be the desired vertices.

The orange is the point on the purple line, the red and blue are what should be the desired vertices.

\$\endgroup\$
8
  • 3
    \$\begingroup\$ How can a point be perpendicular to anything? \$\endgroup\$ Jan 11 '18 at 4:13
  • \$\begingroup\$ Think of it as the line between the point on the line and vertex as what is perpendicular. \$\endgroup\$
    – Dylan
    Jan 11 '18 at 4:27
  • \$\begingroup\$ Wouldn't it be simpler to just calculate the normal vector to the plane that passes through the given point, then use that to determine a point on the plane... then find the nearest vertex (lattice point, I assume) to that? \$\endgroup\$ Jan 11 '18 at 4:58
  • 1
    \$\begingroup\$ You can measure the distance between a point and a plane \$\endgroup\$
    – Jay
    Jan 11 '18 at 6:46
  • 1
    \$\begingroup\$ I don't understand the question. "Think of it as the line between the point on the line and vertex as what is perpendicular." For any line and any point, there is such point on the line that the original line and the line between two points are perpendicular. \$\endgroup\$ Jan 11 '18 at 16:21
1
\$\begingroup\$

Figured out that the dot product math was sound and doing what it was suppose to, but elsewhere I had a space transformation that i didn't need that caused the point on the line to be in a different location. removing that transform fixed my problem.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ As written right now, if another user had a similar problem, reading this answer wouldn't give them much guidance about how to solve it. If you include some examples of the code you changed, or explain your steps in more detail, you might be able to save future gamedevs some time with this problem. :) \$\endgroup\$
    – DMGregory
    Jan 12 '18 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.