Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Behavior of parallelVectors() function

konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,017 ✭✭✭✭✭
I noticed that parallelVectors(v1, v2) returns False if one of the vectors is zero vector, if i remember correctly this behavior goes against the strict mathematical properties of zero vector, which should be parallel to any vector.
For example the condition for point "p" lying on the line defined by reference point "refPoint" and direction vector "refVector" is "parallelVectors(p - refPoint, refVector)" but when "p" matches "refPoint" parallelVectors() returns False, which is rather unexpected and unwanted behavior.

Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 493
    edited December 2017
    Hmm, this one's tricky. I think you found a bug, but even if that bug were fixed, parallelVectors wouldn't quite suit that use case.

    In the case you mentioned of parallelVectors(p - refPoint, refVector), I think a zero check outside the function *is* warranted. If (p - refPoint) is very close to (but not precisely) zero, it quite likely is pointing in some non-parallel direction. If we called that parallel, we'd lose some other important properties, like the property where parallelVectors(K*a, b) returns the same thing for any non-zero K. So for your case, a better check check would be something like:
    norm(cross(p - refPoint, refUnitVector)) < TOLERANCE.zeroLength.
    Alternatively, if you (perhaps rightfully) don't want to think about cross products, just do a zero check (via tolerantEquals) and a parallel check separately.

    For reference, our implementation is not far from that, but it measures an angular deviation rather than a linear one:
    
    export function parallelVectors(vector1 is Vector, vector2 is Vector) returns boolean
    {
        const crossP2 = squaredNorm(cross(vector1, vector2));
        const v1v2 = squaredNorm(vector1) * squaredNorm(vector2);
        return crossP2 < v1v2 * TOLERANCE.zeroAngle * TOLERANCE.zeroAngle;
    }
    The bug I mentioned up top is that I think the < sign should be <=, so for the case where a vector is exactly zero should return true. However, tolerances are tricky, so the fixed version still wouldn't have the property you desire. You care about linear deviation from a parallel line, whereas parallelVectors() cares about angular deviation from parallel angle. These two concepts are two closely related but mathematically distinct once you throw tolerances into the mix!
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,017 ✭✭✭✭✭
    ok, thanks @kevin_o_toole_1
    a little problem with all that built in tolerances is that they are not documented

Sign In or Register to comment.