# How to convert Vector{Point2{Float64}} to Vector{Tuple{Float64, Float64}}:

**URL:** <https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026>\
**Category:** New to Julia\
**Created:** [February 10, 2024, 12:08pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026 "2024-02-10T12:08:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)\
**Post date:** [February 10, 2024, 12:08pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/1 "2024-02-10T12:08:43Z")

</div>

Actually the title says it all. How to perform this conversion ? I haven’t found anything.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [February 10, 2024, 12:15pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/2 "2024-02-10T12:15:25Z")

</div>

Have a look at the function `reinterpret`

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [February 10, 2024, 12:24pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/3 "2024-02-10T12:24:43Z")

</div>

The `Point2` type isn’t part of Julia Base. Which package are you using that defines it? I believe there’s one in Makie, Meshes, and probably a few other geometry or coordinate system related packages.

---

<div class="post-metadata">

**Author:** ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)\
**Post date:** [February 10, 2024, 12:42pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/4 "2024-02-10T12:42:29Z")

</div>

Oh, I didn’t know that,

then lets suppose I got a simple vector like

```julia
using GeometryBasics

v = Point2.(rand(10))

```

this will create a

```julia
10-element Vector{Point2{Float64}}

```

In my eyes it must be possible to convert it to

```julia
10-element Vector{Tuple{Float64, Float64}}

```

this can be easily shown by

```julia
[(v[1][1], v[1][2]), (v[2][1], v[2][2]), (v[3][1], v[3][2])]

```

which will create a vector of the type above.

But I don’t want to to it all manually.

I already tried with a **for-loop** but no success.

---

<div class="post-metadata">

**Author:** ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)\
**Post date:** [February 10, 2024, 12:44pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/5 "2024-02-10T12:44:04Z")

</div>

> [@baggepinnen](#):
>
> reinterpret

Well this is over my head 😅

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [February 10, 2024, 1:00pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/6 "2024-02-10T13:00:35Z")

</div>

```julia-repl
julia> using GeometryBasics

julia> v = rand(Point2{Float64}, 10)
10-element Vector{Point2{Float64}}:
 [0.23398248544355948, 0.02452509374439149]
 [0.27844708107081617, 0.06249289970873717]
 [0.6555220179505118, 0.27570802615639156]
 [0.43663412028067594, 0.7334931851153921]
 [0.7282970726772982, 0.3053395319059993]
 [0.2857930185597616, 0.02425459211368952]
 [0.1996406989985261, 0.8910321768520889]
 [0.9761205749615253, 0.6585221941570446]
 [0.4635527211775988, 0.9869582972102782]
 [0.012031268178171461, 0.7939369315234106]

julia> reinterpret(Float64, v)
20-element reinterpret(Float64, ::Vector{Point2{Float64}}):
 0.23398248544355948
 0.02452509374439149
 0.27844708107081617
 0.06249289970873717
 0.6555220179505118
 0.27570802615639156
 0.43663412028067594
 0.7334931851153921
 0.7282970726772982
 0.3053395319059993
 0.2857930185597616
 0.02425459211368952
 0.1996406989985261
 0.8910321768520889
 0.9761205749615253
 0.6585221941570446
 0.4635527211775988
 0.9869582972102782
 0.012031268178171461
 0.7939369315234106

julia> reinterpret(Tuple{Float64, Float64}, v)
10-element reinterpret(Tuple{Float64, Float64}, ::Vector{Point2{Float64}}):
 (0.23398248544355948, 0.02452509374439149)
 (0.27844708107081617, 0.06249289970873717)
 (0.6555220179505118, 0.27570802615639156)
 (0.43663412028067594, 0.7334931851153921)
 (0.7282970726772982, 0.3053395319059993)
 (0.2857930185597616, 0.02425459211368952)
 (0.1996406989985261, 0.8910321768520889)
 (0.9761205749615253, 0.6585221941570446)
 (0.4635527211775988, 0.9869582972102782)
 (0.012031268178171461, 0.7939369315234106)

```

---

<div class="post-metadata">

**Author:** ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)\
**Post date:** [February 10, 2024, 1:10pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/7 "2024-02-10T13:10:26Z")

</div>

> [@mkitti](#):
>
> `reinterpret(Float64, v)`

Okay, thank you but actually that doesn’t help me in my case.

Probably I should have specified what I plan to do - I want to perform a triangulation for which I need to create boundary points like

```julia
using GeometryBasics, DelaunayTriangulation

points = [(0.0, 0.0), (1.0, 0.0), (1.0, 0.3), (0.8, 0.3), 
(0.8, 0.5), (1.0, 0.5), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)]

boundary_nodes, points = convert_boundary_points_to_indices(points)

```

The points specified here are of type

```julia
9-element Vector{Tuple{Float64, Float64}}

```

However as stated in the title my values are of type

```julia
v = Point2.(rand(9))

9-element Vector{Point2{Float64}}

```

so

```julia
boundary_nodes, points = convert_boundary_points_to_indices(v)

```

doesn’t work

also

```julia
v = reinterpret(Float64,v)

boundary_nodes, points = convert_boundary_points_to_indices(v)

```

does work neither. Any ideas ?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [February 10, 2024, 1:15pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/8 "2024-02-10T13:15:53Z")

</div>

> [@mkitti](#):
>
> `reinterpret(Tuple{Float64, Float64}, v)`

Did you try `reinterpret(Tuple{Float64, Float64}, v)`?

I am confused how you go from 10 `Point2` to 9 `Tuple`?

Also here are a few other approaches.

```julia-repl
julia> getproperty.(v, :data)
10-element Vector{Tuple{Float64, Float64}}:
 (0.23398248544355948, 0.02452509374439149)
 (0.27844708107081617, 0.06249289970873717)
 (0.6555220179505118, 0.27570802615639156)
 (0.43663412028067594, 0.7334931851153921)
 (0.7282970726772982, 0.3053395319059993)
 (0.2857930185597616, 0.02425459211368952)
 (0.1996406989985261, 0.8910321768520889)
 (0.9761205749615253, 0.6585221941570446)
 (0.4635527211775988, 0.9869582972102782)
 (0.012031268178171461, 0.7939369315234106)

julia> Tuple.(v)
10-element Vector{Tuple{Float64, Float64}}:
 (0.23398248544355948, 0.02452509374439149)
 (0.27844708107081617, 0.06249289970873717)
 (0.6555220179505118, 0.27570802615639156)
 (0.43663412028067594, 0.7334931851153921)
 (0.7282970726772982, 0.3053395319059993)
 (0.2857930185597616, 0.02425459211368952)
 (0.1996406989985261, 0.8910321768520889)
 (0.9761205749615253, 0.6585221941570446)
 (0.4635527211775988, 0.9869582972102782)
 (0.012031268178171461, 0.7939369315234106)

```

---

<div class="post-metadata">

**Author:** ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)\
**Post date:** [February 10, 2024, 1:22pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/9 "2024-02-10T13:22:09Z")

</div>

> [@mkitti](#):
>
> `v = rand(Point2{Float64}, 10)`

So doing

```julia
using GeometryBasics, DelaunayTriangulation

v = rand(Point2{Float64}, 10)

v = reinterpret(Tuple{Float64, Float64}, v)

boundary_nodes, points = convert_boundary_points_to_indices(v)

```

gives

```julia
AssertionError: x[begin] ≈ x[end]

```

|

**but when using points that form a closed shape, it does seem to work.**

I’ll check if I can triangulate my polygon with that

* * *

**Edit:** It really does work, thanks again!

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [February 10, 2024, 1:33pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/10 "2024-02-10T13:33:16Z")

</div>

Try `view(v, [1:10,1])`?

```julia-repl
julia> v = rand(Point2{Float64}, 10);

julia> v = reinterpret(NTuple{2,Float64}, v);

julia> v = @view v[[begin:end; begin]]
11-element view(reinterpret(Tuple{Float64, Float64}, ::Vector{Point2{Float64}}), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) with eltype Tuple{Float64, Float64}:
 (0.045284339720533695, 0.9325640220771096)
 (0.3331647565133017, 0.15689121150971186)
 (0.9830499022615393, 0.6216043326795608)
 (0.030846773825717766, 0.5901168577657975)
 (0.17929582192192317, 0.19425072688193035)
 (0.001888257902482482, 0.9545544015748283)
 (0.8675845436130039, 0.48353984366916114)
 (0.8868045558380299, 0.38072206725730584)
 (0.8242620285065096, 0.8430903883691105)
 (0.8322873598355732, 0.8199610284020267)
 (0.045284339720533695, 0.9325640220771096)

```

---

<div class="post-metadata">

**Author:** ![Midez](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Midez](https://discourse.julialang.org/u/Midez)\
**Post date:** [February 10, 2024, 1:35pm UTC](https://discourse.julialang.org/t/how-to-convert-vector-point2-float64-to-vector-tuple-float64-float64/110026/11 "2024-02-10T13:35:18Z")

</div>

> [@Midez](#):
>
> `reinterpret(Tuple{Float64, Float64}, v)`

Again, your simple manipulation

```julia
reinterpret(Tuple{Float64, Float64}, v)

```

did the trick. 😁

About your confusion about 9 or 10 points, it was just an example of different sets. Of course I wanted to convert 1 to 1.
