Wikipedia:Reference desk/Archives/Mathematics/2010 October 1

= October 1 =

Transforming 3 points to a new coordinate plane in 3D Cartesian space
Hello,

I've inherited some C code that, among other things, takes three points specified in one 3D Cartesian coordinate system and (indirectly) converts their coordinates to a new coordinate system. For the first two points, the process by which this is done is quite clear. However, for the third point, I can't seem to figure out how the expressions used to determine the X and Y coordinates of the point were derived. Although I could just assume that the code is working fine and move on, I'd like to understand the logic behind the calculations.

I've included the expressions used to determine the coordinates of the three points in the new coordinate system below. In terms of notation, I refer to the points as P1, P2, and P3; the subscripts denote the coordinate (x, y, or z) and the coordinate system (O = old, N = new). For (hopefully) added clarify, I've made the coordinates specified in the old coordinate system red and those in the new coordinate system blue. The coordinates in the old coordinate system are known prior to these computations.

Point 1

$$ {\color{blue}\mathit{P1}_{xN}} = 0 \, $$

$$ {\color{blue}\mathit{P1}_{yN}} = 0 \, $$

$$ {\color{blue}\mathit{P1}_{zN}} = 0 \, $$

This simply indicates that point 1 is the origin of the new coordinate system.

Point 2

$$ {\color{blue}\mathit{P2}_{xN}} = \sqrt{({\color{red}\mathit{P2}_{xO}} - {\color{red}\mathit{P1}_{xO}})^2 + ({\color{red}\mathit{P2}_{yO}} - {\color{red}\mathit{P1}_{yO}})^2 + ({\color{red}\mathit{P2}_{zO}} - {\color{red}\mathit{P1}_{zO}})^2} \, $$

$$ {\color{blue}\mathit{P2}_{yN}} = 0 \, $$

$$ {\color{blue}\mathit{P2}_{zN}} = 0 \, $$

This is also straight-forward: the intent is clearly for point 2 to lie on the x axis of the new coordinate system and its position on the x axis to be the magnitude of the vector connecting point 1 and point 2 in the original coordinate system (i.e. the distance between them).

Point 3

$$ {\color{blue}\mathit{P3}_{xN}} = \left(\frac{({\color{red}\mathit{P3}_{xO}} - {\color{red}\mathit{P1}_{xO}})({\color{red}\mathit{P2}_{xO}} - {\color{red}\mathit{P1}_{xO}}) + ({\color{red}\mathit{P3}_{yO}} - {\color{red}\mathit{P1}_{yO}})({\color{red}\mathit{P2}_{yO}} - {\color{red}\mathit{P1}_{yO}}) + ({\color{red}\mathit{P3}_{zO}} - {\color{red}\mathit{P1}_{zO}})({\color{red}\mathit{P2}_{zO}} - {\color{red}\mathit{P1}_{zO}})}\right) \, $$

$$ {\color{blue}\mathit{P3}_{yN}} = \sqrt{({\color{red}\mathit{P3}_{xO}} - {\color{red}\mathit{P1}_{xO}})^2 + ({\color{red}\mathit{P3}_{yO}} - {\color{red}\mathit{P1}_{yO}})^2 + ({\color{red}\mathit{P3}_{zO}} - {\color{red}\mathit{P1}_{zO}})^2 - ({\color{blue}\mathit{P3}_{xN}})^2} \, $$

$$ {\color{blue}\mathit{P3}_{zN}} = 0 \, $$

This where things get a bit confusing (for me, at least). Since the new Z coordinate for point 3 is set to zero, clearly points 1, 2, and 3 are being used to define the XY plane of the new coordinate system. Points 1 and 2 have already defined the X axis, so point 3 is then being used to define the orientation of the XY plane overall.

However, I can't figure out how the expressions for $${\color{blue}\mathit{P3}_{xN}} \,$$ and $${\color{blue}\mathit{P3}_{yN}} \,$$ were derived. Logically, I'd imagine that the expression for $${\color{blue}\mathit{P3}_{xN}} \,$$ must represent some sort of projection of point 3 onto the line formed by point 1 and 2, but it's been a long time since I've done projections in 3D and unfortunately the form of this expression doesn't look familiar to me. I'm also unclear on what the expression for $${\color{blue}\mathit{P3}_{yN}} \,$$ is getting at; it's very close to simply being the magnitude of the line connecting points 1 and 3, but then there's the presence of the additional $$({\color{blue}\mathit{P3}_{xN}})^2 \,$$ term to be accounted for.

So, if anyone who has more familiarity with 3D coordinate transformations off the top of their head than I do has a possible explanation of how the expressions for $${\color{blue}\mathit{P3}_{xN}} \,$$ and $${\color{blue}\mathit{P3}_{yN}} \,$$ were derived, I'd be most appreciative!

Thanks,

Hiram J. Hackenbacker (talk) 00:56, 1 October 2010 (UTC)


 * P3xN is the length of the projection of the vector from P1O to P3O to the vector from P1O to P2O. That is P3xN = (P3O - P1O).(P2O - P1O)/||P2O - P1O||, where that "." denotes the dot product (see vector projection). They take advantage of the fact that ||P2O - P1O|| has already been calculated, since it's P2xN.  P3yN is then just chosen in such a way to ensure that ||P3N|| = ||P3O - P1O|| since those need to be equal. Rckrone (talk) 03:48, 1 October 2010 (UTC)


 * Thanks, Rckrone - that clears it up. Hiram J. Hackenbacker (talk) 11:56, 1 October 2010 (UTC)

Poincaré-Hopf Theorem
Assume that M is a compact, orientable, smooth manifold. Does the Poincaré-Hopf theorem tell us that a smooth vector field on M will have at most χ(M) zeros? If not then can someone give a counter example, e.g. a smooth vector field on the torus with two zeros: one with index −1 and one with index +1. — Fly by Night  ( talk )  09:29, 1 October 2010 (UTC)
 * No it doesn't mean that (that would be the converse). I can't think at the moment of an example exactly like you say, but here's the standard example of a vector field on the torus with four zeros: Stand the torus up on vertically on its end, and dump syrup on the top of it. The syrup will flow down the torus, and use this flow to define a vector field. This will have four zeros: one at the top (source), one at the bottom (sink), and one at each of the top and bottom of the inner circle (saddles). So there's 4 zeros, of index +1, +1, -1, -1. (This example, with a good picture, is in Guillemin + Pollack's Differential Topology.) You can probably tweak this to make it have 2 zeros. Staecker (talk) 11:53, 1 October 2010 (UTC)

basic combinatorics
I am trying to deduce a formula for the number of partitions of an integer, say f(n) where order of the integers dont matter. For example 4 can be written in 8 ways: 4, 2+2, 1+3, 3+1, 1+1+1+1, 1+2+1, 2+1+1, 1+1+2, so f(4)=8. This is how I proceeded: First I already had a proof of this statement: If A is the set $$\{(x_1,...x_k) : x_1 + ... + x_k = n, n\in N\}$$ then A has cardinality $$\tbinom{n+k-1}{k-1}$$. Since we basically need to count the number of elements in the set $$\{(x_1,...x_k) : x_1 + ... + x_k = n, 1\le k \le n\}$$, so this number is $$\textstyle\sum_{k=1}^{n}\tbinom{k+n-1}{k-1}$$. How can I simplify this to get $$2^{n-1}$$ which is supposed to be the answer. Or is there an easier way find f(n)? Thanks. Also regarding the fact of which I already have a proof of, namely, A has cardinality $$\tbinom{n+k-1}{k-1}$$, the proof I have relies on an argument of making bars in between blanks, and actually deals with making selections with repetitions. Is there a wikipedia article about this technique. Thanks-Shahab (talk) 11:14, 1 October 2010 (UTC)
 * First see Bell number. Then see Multiset and stars and bars (probability). Bo Jacoby (talk) 11:20, 1 October 2010 (UTC).
 * I have read them, thanks. "Stars and bars" answers my second question completely. But I am still at a loss for showing $$\textstyle\sum_{k=1}^{n}\tbinom{k+n-1}{k-1}=2^{n-1}$$ to answer my original question. Also I am not sure why you linked Bell numbers.-Shahab (talk) 11:50, 1 October 2010 (UTC)
 * The arrangements that you are counting are called compositions. Since each of your xi must be at least 1, the cardinality of A, the compositions of n with k parts, is in fact
 * $$\tbinom{n-1}{k-1}$$
 * It is true that
 * $$\sum_{k=1}^{n}\tbinom{n-1}{k-1} = 2^{n-1}$$
 * but a simpler way to count the total number of compositions of n is given in Composition (number theory). Gandalf61 (talk) 11:52, 1 October 2010 (UTC)
 * Thanks a ton!-Shahab (talk) 12:12, 1 October 2010 (UTC)

using CAS to find the catenary parameter a that will give us a curve that will pass through a given point
I want to find the equation of a catenary curve that will pass through the origin and a given (x,y) and (-x,y).

I see that a catenary is described by y=a*cosh(x/a). Since I want my curve to pass through the origin I will just subtract a to move it down to zero at x=0 so my new equation becomes y=a*cosh(x/a)-a. I figure that I can just solve for a in terms of the other variables but when I try to use a CAS (like ti-89 and wolframalpha) I get strange results. If i substitute actual values for x and y I can get a correct approximate numerical result but I cannot get a general equation of a in terms of x and y.

I am expecting that there can only be one value of a to satisfy a given (x,y) but apparently I am wrong. I have tried restricting the domains of a,x and y positive numbers less than infinity but I still can't work it out. Why can't I get a simple single result for a? Thanks so much. --- Diletante (talk) 20:41, 1 October 2010 (UTC)
 * I think a numerical solution is the best you can hope for since there isn't a way to solve for a with standard functions. The good news is that it's pretty easy reduce the problem to finding the inverse of a single function, namely (1/x)(cosh x -1).--RDBury (talk) 04:27, 2 October 2010 (UTC)


 * Set &alpha;=1/a. Then your equation y=a*cosh(x/a)&minus;a is written cosh(x&alpha;)&minus;y&alpha;&minus;1=0. The left hand side is a nice entire function of &alpha;, and the equation is solved by a root-finding algorithm. Bo Jacoby (talk) 10:48, 2 October 2010 (UTC). The uninteresting solution &alpha;=0 is removed by division: $$\textstyle -y+\frac{\cosh(x\alpha)-1}{\alpha}=0$$, and the series expansion is $$\scriptstyle -y+\frac{x^2}{2!}\alpha+\frac{x^4}{4!}\alpha^3+\cdots=0$$. The first approximation $$\scriptstyle \alpha=\frac{2y}{x^2}$$ is improved by Newton's method. Bo Jacoby (talk) 21:54, 2 October 2010 (UTC).

Thanks for the good answers. I will be honest and say that all this is a little bit beyond my ability to understand, but I am going to try my best to remember what I learned about approximation in cal 2 and read the articles Bo Jacoby linked. Thanks alot everyone! -- Diletante (talk) 02:08, 3 October 2010 (UTC)
 * Your premise is correct: Given $$x\neq0$$ and y, there is a unique value a for which y=a*cosh(x/a)-a. There is thus a function $$f(x,y)$$ which gives for any values of x and y the corresponding value of a. However, just because the function exists doesn't mean it can be described in a nice "traditional" form, and indeed this function cannot. What you do next depends on your application. If you just want to be able to take numerical values of x, y and get a, I understand your calculator can already do this for you. You can also find a formula which gives an approximate answer. For example, if x is much larger than y, then $$a\cosh(x/a)-a \approx \frac{x^2}{2a}+\frac{x^4}{24a^3}$$, and you can solve that to find an approximate formula for a. -- Meni Rosenfeld (talk) 10:03, 3 October 2010 (UTC)


 * Ok I hope you all will indulge me for a little bit longer. I see that we can do a taylor series to approximate my f(x)=y.  I see that we can solve the 2nd order taylor approximation to get a=2y/x^2. What i do not understand is how I can solve for a for greater orders of the taylor approximation (like the last approximation Meni gave). I take it that this is why Bo Jacoby suggested using the first approximation as a starting point to use newton's method, but I don't understand what that really means.  Will newtons method allow me to write a better approximation of a algebraically, or just help me find a numerical result?  In short, how can I write an approximation that is a little better than a=2y/x^2? -- 21:32, 3 October 2010 (UTC)
 * Newton's method is just for numerical results.
 * To solve the approximation I gave, you can use the method to solve cubic equations. But there's a better way to approach this.
 * Following RDBury's suggestion, we let $$g(b)=\frac{\cosh b-1}{b}$$. We can show that $$f(x,y)=\frac{x}{g^{-1}(y/x)}$$. Then we just need to find an approximation for $$g^{-1}$$. The series expansion of g is $$g(b) = \frac b2+\frac{b^3}{24}+\frac{b^5}{720}+\cdots$$, and with some algebraic manipulations we can find as many terms as we want of the expansion $$g^{-1}(c)=2c-\frac{2c^3}{3}+\frac{26c^5}{45}+\cdots$$. Plugging this in, we can find $$f(x,y) = \frac{x^2}{2y}+\frac y6-\frac{4y^3}{45x^2}+\cdots$$.
 * Again, this is good for small y. You can also find an approximation good for large y. Also, for any given $$y/x$$, you can numerically find the value and derivatives of g around that point, and from that find an expression for the values of f around it (so you can get, for example, a formula which is good when $$y\approx5x$$). -- Meni Rosenfeld (talk) 08:56, 4 October 2010 (UTC)


 * You want to find the value of $$\scriptstyle \alpha$$ for which $$\scriptstyle f(\alpha)$$ = 0, where $$\scriptstyle f(\alpha)$$ = $$\scriptstyle \frac{\cosh(x\alpha)-1-\alpha y}{\alpha}$$ ≈ $$\scriptstyle \frac{x^2}{2}\alpha-y.$$ A first approximation is $$\scriptstyle \alpha_1$$ = $$\scriptstyle \frac{2y}{x^2}.$$ The derivative is, according to the quotient rule, $$\scriptstyle f'(\alpha)$$ = $$\scriptstyle \frac{x\alpha\sinh(x\alpha)-\cosh(x\alpha)+1}{\alpha^2}.$$ Newton's method is not just for numerical results. The second Newton approximation is $$\scriptstyle \alpha_2$$ = $$\scriptstyle \alpha_1-\frac{f(\alpha_1)}{f'(\alpha_1)}$$ = $$\scriptstyle \frac{\alpha_1f'(\alpha_1)-f(\alpha_1)}{f'(\alpha_1)}$$  or
 * $$ \alpha_2=\frac{\frac{x\alpha_1\sinh(x\alpha_1)-\cosh(x\alpha_1)+1}{\alpha_1}-\frac{\cosh(x\alpha_1)-1-y\alpha_1}{\alpha_1}}{\frac{x\alpha_1\sinh(x\alpha_1)-\cosh(x\alpha_1)+1}{\alpha_1^2}}$$ $$= \alpha_1\frac{x\alpha_1\sinh(x\alpha_1)-2\cosh(x\alpha_1)+2+y\alpha_1 }{x\alpha_1\sinh(x\alpha_1)-\cosh(x\alpha_1)+1}$$
 * This approximation $$\alpha_2$$ is a little better than $$\alpha_1$$ = $$\frac{2y}{x^2}$$. Don't forget that $$a=\frac 1 \alpha$$. So:
 * $$a_1=\frac{x^2}{2y}$$
 * $$ a_2=\frac{x^2}{4y}\frac{\frac{2y}{x}\sinh(\frac{2y}{x})-\cosh(\frac{2y}{x})+1}{\frac yx(\sinh(\frac{2y}x)+\frac yx)-\cosh(\frac{2y}x)+1}$$
 * Bo Jacoby (talk) 13:19, 5 October 2010 (UTC).