Programming constraints in video game. How are these two equations equal?

103 Views Asked by At

I'm currently working on programming a game that uses a physics engine (NAPE). Inside of that engine there are constraints that you can program. In order to program those you need a somewhat advanced understanding of math.... which I don't currently have. I'm at the highschool level of algebra/trig/calculus. I've spent the last two weeks doing a lot of learning and yet I'm still having difficulty understanding it. This is the current document that I'm working off of.

http://napephys.com/help/Constraints.pdf

I've been following it along to the best of my ability. I'm currently stuck in section 3.1 predefined constraints - PivotJoint (page 4)

I understand how and why the position constraint and velocity equal the zero vector. Where I'm currently stuck is how the two velocity equations are equal

$$ V(\vec{v}) = (\vec{v}_2 + w_2 \vec{r}_2) - (\vec{v}_1 + w_1 \vec{r}_1) $$

This is what I interpreted the velocity equation as from looking at the code in the class (page 13 - __velocity function). In the PDF it is written as:

$$ V(\vec{v}) = (\vec{v}_2 + w_2 \times \vec{r}_2) - (\vec{v}_1 + w_1 \times \vec{r}_1) $$

I'm assuming here that it's just normal multiplication between $w_2$ and $\vec{r}_2$ and not a cross product. Because $w_2$ is a scalar and I'm under the impression that you can't do the cross product with a scalar.

In the next line in the PDF this equation is equal to the one above:

$$ V(\vec{v}) = -E_2 \vec{v}_1 - [\vec{r}_1]_x w_1 + E_2 \vec{v}_2 - [\vec{r}_2]_x w_2 $$

I see that they are expanding the brackets. I'm assuming that they are multiplying the brackets by 1 and -1. I'm assuming that $-E_2$ is the 2x2 identity matrix. Hence it is the same as multiplying a vector by 1. What has me confused is the order for $\vec{r}_2$ and $w_2$ have been switched. And the $[\vec{r}_2]_x$ is a 90 degree turn counter clockwise. I don't see how that happens. Can someone explain that to me? Or walk me through the steps on how you get from one version of the equation to the other?

For some extra simplifying this is what I know about the variables from studying the document/code.

$$ \vec{v}_1, \vec{v}_2 = \mathbb{R}^3\\ \vec{r}_1, \vec{r}_2 = \mathbb{R}^2 \\ w_1, w_2 = scalar\\ [\vec{r}_1]_x =\begin{pmatrix} -r_y\\ r_x\\ \end{pmatrix} $$

If anybody could help me, it would be much appreciated. Also, please remember that I'm not an expert at this stuff, hence why I'm here. You might have to explain things a bit more.

1

There are 1 best solutions below

4
On

I think the main problem is that you didn't see that they defined $w\times \vec{r}:= w[\vec{r}]_x$ (this is done under ''overloading the $\times$ operator''). So \begin{align} V(\vec{v}) &= -\mathbf{E}_2\vec{v}_1-[\vec{r}_1]_xw_1+\mathbf{E}_2\vec{v}_2+[\vec{r}_2]_xw_2\\ &=-\mathbf{E}_2\vec{v}_1-w_1[\vec{r}_1]_x+\mathbf{E}_2\vec{v}_2+w_2[\vec{r}_2]_x\\ &=-\vec{v}_1-w_1\times\vec{r}_1+\vec{v}_2+w_2\times\vec{r}_2\\ &=(\vec{v}_2+w_2\times\vec{r}_2)-(\vec{v}_1+w_1\times\vec{r}_1), \end{align} as wanted.