vector question

papawo
papawo Member, Developers Posts: 206 PRO

Comments

  • mahir
    mahir Member, Developers Posts: 1,324 ✭✭✭✭✭
    Vectors can indicate several things - 3D direction, 3D position, 2D position, location on a surface, and probably more that I don't recall. Some of these don't require units; some do. Specifically, direction doesn't need units, but position does. If you're trying to sketch a rectangle, you are feeding the skRectangle function the position of two points. If units are not included, that (1,1) could be (1,1)*inch or (1,1)*meter. So instead of trying to assume a unit, which would probably lead to errors along the way, the function was written to require explicit units. I hope I explained that well enough :smile:
  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,277 image
    The reason is that 1 is a number, while 1 * inch is a length. The locations of rectangle corners are lengths (distances from plane's origin), not numbers, so skRectangle doesn't work without the *inch. The reason we did it this way (as opposed to treating everything as a number) is to catch common errors earlier in the design process (so, e.g., adding 2 * inch + 3 * degree will lead to an error, rather than an unintended result that could slip into manufacturing) by forcing the programmer/engineer to think about units explicitly.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    When referring to a position on a sketch, you need to specify a distance along the X-and Y-axes of the sketch. These distances need to have length units, and can be created in many ways — vector(1, 0) * inch means something different form vector(1, 0) * meter, which means something different from vector(1, 0) * definition.radius, but all of these represent a certain distance along the X-axis, and zero distance along the Y-axis. 

    Under the hood, multiplying vector(1, 0) (a Vector) by inch (a ValueWithUnits) will multiply each component of the vector by the value, resulting in a vector that specifies two distances along the X-and Y-axes, which is what the argument for skRectangle expects.

  • papawo
    papawo Member, Developers Posts: 206 PRO
    edited October 2016
    Thank you ! Ilya , kevin & Mahir . Now its all clear! :)