5
$\begingroup$

I think this question is very simple and will be closed, but I'm left with doubts.

transform = CoordinateTransformData["Polar" -> "Cartesian", "Mapping"];
{p1, p2, p3, p4, p5, p6} = 
 transform[{2 Sqrt[3], # Degree}] & /@ Most[Subdivide[360, 6] + 30] //
   N

$\left( \begin{array}{cc} 3. & 1.73205 \\ 0. & 3.4641 \\ -3. & 1.73205 \\ -3. & -1.73205 \\ 0. & -3.4641 \\ 3. & -1.73205 \\ \end{array} \right)$

How could I apply the insert function to get this result?

Join[{{3., 1.7320508075688772, 0}, {0., 3.4641016151377544, 0}, {-3., 
   1.7320508075688772, 0}, {-3., -1.7320508075688772, 
   0}, {0., -3.4641016151377544, 0}, 
     {3., -1.7320508075688772, 0}}, {{3., 1.7320508075688772, 
   15}, {0., 3.4641016151377544, 15}, {-3., 1.7320508075688772, 
   15}, {-3., -1.7320508075688772, 15}, {0., -3.4641016151377544, 15}, 
     {3., -1.7320508075688772, 15}}]

$\left( \begin{array}{ccc} 3. & 1.73205 & 0 \\ 0. & 3.4641 & 0 \\ -3. & 1.73205 & 0 \\ -3. & -1.73205 & 0 \\ 0. & -3.4641 & 0 \\ 3. & -1.73205 & 0 \\ 3. & 1.73205 & 15 \\ 0. & 3.4641 & 15 \\ -3. & 1.73205 & 15 \\ -3. & -1.73205 & 15 \\ 0. & -3.4641 & 15 \\ 3. & -1.73205 & 15 \\ \end{array} \right)$

$\endgroup$
4
  • $\begingroup$ Have you tried PadRight? $\endgroup$
    – lowriniak
    Dec 20, 2016 at 11:13
  • $\begingroup$ Not yet. I will read about it. $\endgroup$
    – user45104
    Dec 20, 2016 at 11:47
  • $\begingroup$ I think there no solution with Insert only. Otherwise there are plenty of solutions. I would do something like this : Join[Insert[#, 0, -1] & /@ {p1, p2, p3, p4, p5, p6}, Insert[#, 15, -1] & /@ {p1, p2, p3, p4, p5, p6}] $\endgroup$
    – andre314
    Dec 20, 2016 at 11:58
  • $\begingroup$ Related: mathematica.stackexchange.com/q/7996/121 $\endgroup$
    – Mr.Wizard
    Dec 21, 2016 at 22:28

3 Answers 3

5
$\begingroup$

Using lowriniak's comment:

transform = CoordinateTransformData["Polar" -> "Cartesian", "Mapping"];
{p1, p2, p3, p4, p5, p6} = 
 transform[{2 Sqrt[3], # Degree}] & /@ Most[Subdivide[360, 6] + 30] //
   N

$\left( \begin{array}{cc} 3. & 1.73205 \\ 0. & 3.4641 \\ -3. & 1.73205 \\ -3. & -1.73205 \\ 0. & -3.4641 \\ 3. & -1.73205 \\ \end{array} \right)$

Through PadRight function:

Join[PadRight[{p1, p2, p3, p4, p5, p6}, {6, 3}], 
 PadRight[{p1, p2, p3, p4, p5, p6}, {6, 3}, {15}]]

$\left( \begin{array}{ccc} 3. & 1.73205 & 0 \\ 0. & 3.4641 & 0 \\ -3. & 1.73205 & 0 \\ -3. & -1.73205 & 0 \\ 0. & -3.4641 & 0 \\ 3. & -1.73205 & 0 \\ 3. & 1.73205 & 15 \\ 0. & 3.4641 & 15 \\ -3. & 1.73205 & 15 \\ -3. & -1.73205 & 15 \\ 0. & -3.4641 & 15 \\ 3. & -1.73205 & 15 \\ \end{array} \right)$

$\endgroup$
3
$\begingroup$

Behold ArrayFlatten

pn = {p1, p2, p3, p4, p5, p6};

ArrayFlatten[{{pn, 0}, {pn, 15}}] // MatrixForm

$\left( \begin{array}{ccc} 3. & 1.73205 & 0 \\ 0. & 3.4641 & 0 \\ -3. & 1.73205 & 0 \\ -3. & -1.73205 & 0 \\ 0. & -3.4641 & 0 \\ 3. & -1.73205 & 0 \\ 3. & 1.73205 & 15 \\ 0. & 3.4641 & 15 \\ -3. & 1.73205 & 15 \\ -3. & -1.73205 & 15 \\ 0. & -3.4641 & 15 \\ 3. & -1.73205 & 15 \\ \end{array} \right)$

$\endgroup$
3
$\begingroup$

Also

Distribute[{{0, 15}, pn}, List, List, List, Append[#2, #] &] // MatrixForm

or

Join @@ Outer[Append[#2, #] &,  {0, 15}, pn, 1] // MatrixForm

Mathematica graphics

Note: you can use Insert[#2, #, -1] & instead of Append[#2, #] in the above.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.