Is it possible to get the tension in a segment of a cable system, rather than just the maximum tension in the entire cable? I have a cable attached to a winch which then goes through several rings and finally ends at an attachment point. I need to be able to measure the tension in the cable at the starting point of the segment attached to the winch, as it spools the cable in and out. How might I do this?
You are getting an access violation. Your code does something it is not allowed to do. Your issue is likely in the following lines of code.
auto assem_iter = registeredAssemblies.begin() + 1; VxAssembly* someassembly = *assem_iter; const VxConstraintSet& constraintsinassembly = someassembly->getConstraints(); auto cons_iter = constraintsinassembly.end() - 2; VxConstraint* cons = *cons_iter;
In the code above, cons_iter or assem_iter might become invalid by the shifting you are doing. They might end up pointing to memory locations outside of your container. When you then dereference them (Ex: *cons_iter), you would get a read access violation.
You should not go about and manipulate iterators this way. That's not safe.
For example, just so you know, end() is not pointing to the last element, but is used to indicate the end of the container. It can be understood as pointing to an invalid "marker" element behind the last valid element in a container. And this element can not be safely accessed and would throw a read access violation when you try to dereference it (Ex: *iter).
Hence for iteration in a for loop one commonly uses for (auto iter = container.begin(); iter != container.end(); ++iter) and stops when iter reaches end() without ever reading iter at this point.
If you want to get the "n'th" element in a container (where the first element is defined by n = 0) you should use
auto iter = container.begin(); std::advance(iter, n);
In this example, the returned iterator points to an element in the container and can be safely dereferenced (*iter) only if the container contains n+1 elements.