dilevin / computer-graphics-mass-spring-systems

Computer Graphics Assignment – Mass Spring Systems
1 stars 2 forks source link

How to add pinned vertex penalty #30

Open Hasnat-Khan opened 10 months ago

Hasnat-Khan commented 10 months ago

I am very confused about how to add the quadratic term of the pinned vertices to the Q matrix. I calculated the derivative of the quadratic term, and since p is a nx3 matrix, the size of the entire derivative is nx3. But the size of the Q matrix is nxn so I'm not sure how I'm supposed to add them together.

Second, the assignment notes say to add the linear term to b and it also says so in the tut handout, but in the image it shows it being added to y instead of b. Is y just the part of b that remains constant for all the iterations, so we can just add it to y, or is there a mistake and we should add it to b? image

junior-stack commented 10 months ago

I also encounter this problem. Have u figured it out?

johnnyjly commented 10 months ago

For the first one please check your derivative again (see the recall part in Matrices section in Readme). It should also be n by n. For the second part yes y remains constant because only b is dependent on d which is changing during iterarions. (This is also how I implemented that and it works somehow.)

junior-stack commented 10 months ago

As I apply the formula in Recall section, since Y is wC^T C and x is p, the Y in the formula is an nxn matrix and x is nx3 matrix, it still gives me an n by 3 matrix instead of an n by n matrix. I am not sure what assumption I have ignored or misunderstood?

johnnyjly commented 10 months ago

We are adding an additional quadratic energy term so that means you have to add it to the original energy term and do the optimization. In other words, you'll have Qp = b -> (Q+...)p = b + ... Is that clear?

junior-stack commented 10 months ago

Can you elaborate more? I am trying to understand, but don't get how is your equation related to the dimension of the derivative of the quadratic term

johnnyjly commented 10 months ago

I meant you just take the derivative with respect to p and combine the terms that multiply with p... So that's why it has and should have the same dimension as Q.

Hasnat-Khan commented 10 months ago

Ok I got it to work, but I don't think its explained very well in the tutorial notes or the assignment page. The trace also makes it even more confusing. image I basically just added both the pinned vertex terms to the last line, combined them into 2 traces again, one term combines with the Q term and one term combines with the b term. I just assumed you can combine 2 traces together, since its just the sum of the diagonal. And then I took the derivative. It does not sound like this is at all what we were supposed to do, but it did work and makes much more sense to me, so maybe it'll work for you too @junior-stack ?

johnnyjly commented 10 months ago

This is exactly what you are supposed to do. (Also you don't have to combine the trace before doing the derivative)

Hasnat-Khan commented 10 months ago

Oh I see it now! I guess it was confusing because it says to take the derivative, and add that entire quadratic term (including the p) to Q instead of adding it to this optimization problem, which would factor out the extra p.

Thank you! Your comment about how we are adding an additional penalty energy term is what helped me understand!