nature of code exercise 1.4

edited June 2016 in How To...

I was following this book example and they gave this little exercise and I cant figure out what I’m supposed to do and the book never gives the solution.

how do I calculate the limit of a vector? here is the exercise.

void limit(float max) {
  if (_______ > _______) {

i am trying to accomplish something like this


to get some background here is the link to said exercise.


void limitt(float max){
    if(max > 10){


  • It asks you to write your own limit function for learning purposes, as this method is already included in PVector class. Look, you need to check if magnitude is greater then max and if so, it should be reset back to max, so it would never be higher than this value.

  • i imagine he wants normalise and multiple functions in the gaps - the first will restrict the vector to length 1, the second will multiple it to the required max length.

  • Answer ✓

    I got it, just thinking to complicated. I edit the post with my answer. Thanks for your replies.

  • Take notice that setMag() method is exactly normalize() + mult(): ;;)

Sign In or Register to comment.