<p>I have the following problem I am currently facing.</p>
<p>I am creating the vertices for a cone based on the number of segments and the radius of the base and top.</p>
<p>This is done as follows:</p>
<pre class="lang-cpp prettyprint-override"><code>#include &lt;cmath&gt;
#include &lt;fstream&gt;
#include &lt;numbers&gt;
#include &lt;iostream&gt;
#include &lt;fmt/core.h&gt;

struct Vec3D
{
    double x, y, z;
    Vec3D(double x, double y, double z) : x(x), y(y), z(z) {}
};

int main()
{
    int n = 4;       // number of segments
    double r1 = 0.8; // radius of the base, assume meters
    double r2 = 1.0; // radius of the top, assume meters
    double h = 1.0;  // height of the cone, assume meters

    auto get_coordinates = [&amp;n](int32_t vertex_id, double radius, double height) {
        double theta = vertex_id * 2 * std::numbers::pi / n;
        double x = radius * cos(theta);
        double y = radius * sin(theta);
        double z = height;

        return Vec3D(x, y, z);
    };

    for (int i = 0; i &lt; n; i++)
    {
        Vec3D pt = get_coordinates(i, r1, 0.0);
        std::cout &lt;&lt; fmt::format(&quot;v {} {} {}\n&quot;, pt.x, pt.y, pt.z);
        pt = get_coordinates(i, r1, h);
        std::cout &lt;&lt; fmt::format(&quot;v {} {} {}\n&quot;, pt.x, pt.y, pt.z);
    }
}
</code></pre>
<p>(godbolt: <a href="https://godbolt.org/z/njdxznj9c" rel="nofollow noreferrer">https://godbolt.org/z/njdxznj9c</a>)</p>
<p>Which works perfectly fine, but now I want to automatically create a UV map, which of course in a cylinder case can be very straight forward by just
distributing the uv coordinates for the top vertices between <code>[0, 1]</code> for <code>u</code> and <code>v = 1.0</code>, and for the bottom the same with <code>v = 0.0</code>.</p>
<p>Now in a cone case this would lead to texture distorting.. which I want to avoid and therfore find an arc-like mapping, such that if the printed texture has the correct ratios and sizes (to the actual cup) you can wrap it without distortion, basically the same as blender can do</p>
<p><a href="https://i.sstatic.net/4mFeh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4mFeh.png" alt="Blender UV Unwrapping" /></a></p>
<p>Assuming now only calculating the following points a, b, c, d
my plan was that those points should be possible to calculate and from there on use some sort-of arc parametrisation based on the radii to calculate the other points.
points <code>a</code> and <code>b</code> can be calculated under the assumptions of the coordinates that it is in relation to the ratio of the 2 cone radii.</p>
<p>But I am not really sure how to follow up on that.</p>
<p><a href="https://i.sstatic.net/f1L3C.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/f1L3C.jpg" alt="Sketch of uv map" /></a></p>
<p>I'm glad for any help on that.</p>

<3d><geometry><uv-mapping>
Creating a UV Map for a 3D Cone
Anima
# Creating a UV Map for a 3D Cone

(Asked by: username_0 on 2023-03-24)

I have the following problem I am currently facing.
I am creating the vertices for a cone based on the number of segments and the radius of the base and top.
This is done as follows:
#include 
#include 
#include 
#include 
#include 

struct Vec3D
{
    double x, y, z;
    Vec3D(double x, double y, double z) : x(x), y(y), z(z) {}
};

int main()
{
    int n = 4;       // number of segments
    double r1 = 0.8; // radius of the base, assume meters
    double r2 = 1.0; // radius of the top, assume meters
    double h = 1.0;  // height of the cone, assume meters

    auto get_coordinates = [&n](int32_t vertex_id, double radius, double height) {
        double theta = vertex_id * 2 * std::numbers::pi / n;
        double x = radius * cos(theta);
        double y = radius * sin(theta);
        double z = height;

        return Vec3D(x, y, z);
    };

    for (int i = 0; i < n; i++)
    {
        Vec3D pt = get_coordinates(i, r1, 0.0);
        std::cout << fmt::format("v {} {} {}\n", pt.x, pt.y, pt.z);
        pt = get_coordinates(i, r1, h);
        std::cout << fmt::format("v {} {} {}\n", pt.x, pt.y, pt.z);
    }
}

(godbolt: https://godbolt.org/z/njdxznj9c)
Which works perfectly fine, but now I want to automatically create a UV map, which of course in a cylinder case can be very straight forward by just
distributing the uv coordinates for the top vertices between [0, 1] for u and v = 1.0, and for the bottom the same with v = 0.0.
Now in a cone case this would lead to texture distorting.. which I want to avoid and therfore find an arc-like mapping, such that if the printed texture has the correct ratios and sizes (to the actual cup) you can wrap it without distortion, basically the same as blender can do

Assuming now only calculating the following points a, b, c, d
my plan was that those points should be possible to calculate and from there on use some sort-of arc parametrisation based on the radii to calculate the other points.
points a and b can be calculated under the assumptions of the coordinates that it is in relation to the ratio of the 2 cone radii.
But I am not really sure how to follow up on that.

I'm glad for any help on that.

**Tags:** 3d, geometry, uv-mapping

---

## 0 answers

