How do I convert a polar formula for a circle, to a circle based on a higher norm?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm not even sure how to succinctly ask this question in the title, so let me explain.



I occasionally find myself wanting to map a number to a color in RGB space. I usually do this by expressing a circle in 3d as a function of an angle. As an aid in designing this mapping, I decided to put together a shiny app that visualizes the line in RGB space. This started off as a plain old circle in 3d space, using trigonometric functions, but then I realized I can get some fairly crazy curves (and thus interesting color mappings) by fiddling with the phase, radius, wavelength etc.



library(plotly)
library(shiny)

xPhase = 20
yPhase = 120
zPhase = 240
xCenter = 127
yCenter = 127
zCenter = 127
xWavelength = 1
yWavelength = 1
zWavelength = 1
zRadRadius = 0
xRadius = 100
yRadius = 100
zRadius = 100

gcd = function(args)
if (any(args <= 0))

stop("All arguments to gcd must be positive")

if (length(args) < 2)

stop("Invalid number of arguments")

a = args[1]
b = args[2]
r = a %% b
if (r > 0)

return(gcd(c(b,r,args[-c(1,2)])))

else if (length(args) > 2)

return(gcd(c(b,args[-c(1,2)])))

else

return(b)



lcm = function(args)
if (any(args <= 0))

stop("All arguments to gcd must be positive")

if (length(args) < 2)

stop("Invalid number of arguments")

g = gcd(args[1:2])
m = prod(args[1:2])/g
if (length(args)>2)

return(lcm(c(m,args[-c(1,2)])))

else

return(m)



maxTheta = lcm(c(xWavelength,yWavelength,zWavelength))*360
theta = 0:maxTheta

x = cos(((theta + xPhase) / xWavelength) / 180 * pi) * xRadius + xCenter
y = cos(((theta + yPhase) / yWavelength) / 180 * pi) * yRadius + yCenter
z = cos(((theta + zPhase) / zWavelength) / 180 * pi) * zRadius + zCenter
colors = rgb(x, y, z, maxColorValue = 255)
data = data.frame(theta = theta, x = x, y = y, z = z, colors = colors, avg = apply(cbind(x,y,z),1,mean))

p <- plot_ly(data, x = ~x, y = ~y, z = ~z, colors = ~colors, type = 'scatter3d', mode = 'lines',
opacity = 1, line = list(width = 6, reverscale = FALSE, color = ~colors)) %>%
layout(
scene = list(
xaxis = list(range = c(0,255)),
yaxis = list(range = c(0,255)),
zaxis = list(range = c(0,255)),
aspectmode = "cube"
)
)

print(p)


The above R code generates a simple cirlce in 3d, but set one of the wavelengths to a higher integer and then it gets more interesting.



Sine/Cos functions are defined in terms of a unit circle, where $x^2 + y^2 = r^2$, so my function maps an angle to a some point in the set of points that is a fixed 2norm distance form the center.



I don't like how the curves tend not to explore the corners of the cube so I want to try above concept based on a higher norm. For example, $x^3 + y^3 = r^3$. Is there a simple way of achieving this?
I can do this for a single loop by parameterizing in terms of a dummy variable (t) and just walking along the curve based on a start location and gradient, but then I won't be able to fiddle with the phase/wavelength etc, or can I?







share|cite|improve this question


























    up vote
    0
    down vote

    favorite












    I'm not even sure how to succinctly ask this question in the title, so let me explain.



    I occasionally find myself wanting to map a number to a color in RGB space. I usually do this by expressing a circle in 3d as a function of an angle. As an aid in designing this mapping, I decided to put together a shiny app that visualizes the line in RGB space. This started off as a plain old circle in 3d space, using trigonometric functions, but then I realized I can get some fairly crazy curves (and thus interesting color mappings) by fiddling with the phase, radius, wavelength etc.



    library(plotly)
    library(shiny)

    xPhase = 20
    yPhase = 120
    zPhase = 240
    xCenter = 127
    yCenter = 127
    zCenter = 127
    xWavelength = 1
    yWavelength = 1
    zWavelength = 1
    zRadRadius = 0
    xRadius = 100
    yRadius = 100
    zRadius = 100

    gcd = function(args)
    if (any(args <= 0))

    stop("All arguments to gcd must be positive")

    if (length(args) < 2)

    stop("Invalid number of arguments")

    a = args[1]
    b = args[2]
    r = a %% b
    if (r > 0)

    return(gcd(c(b,r,args[-c(1,2)])))

    else if (length(args) > 2)

    return(gcd(c(b,args[-c(1,2)])))

    else

    return(b)



    lcm = function(args)
    if (any(args <= 0))

    stop("All arguments to gcd must be positive")

    if (length(args) < 2)

    stop("Invalid number of arguments")

    g = gcd(args[1:2])
    m = prod(args[1:2])/g
    if (length(args)>2)

    return(lcm(c(m,args[-c(1,2)])))

    else

    return(m)



    maxTheta = lcm(c(xWavelength,yWavelength,zWavelength))*360
    theta = 0:maxTheta

    x = cos(((theta + xPhase) / xWavelength) / 180 * pi) * xRadius + xCenter
    y = cos(((theta + yPhase) / yWavelength) / 180 * pi) * yRadius + yCenter
    z = cos(((theta + zPhase) / zWavelength) / 180 * pi) * zRadius + zCenter
    colors = rgb(x, y, z, maxColorValue = 255)
    data = data.frame(theta = theta, x = x, y = y, z = z, colors = colors, avg = apply(cbind(x,y,z),1,mean))

    p <- plot_ly(data, x = ~x, y = ~y, z = ~z, colors = ~colors, type = 'scatter3d', mode = 'lines',
    opacity = 1, line = list(width = 6, reverscale = FALSE, color = ~colors)) %>%
    layout(
    scene = list(
    xaxis = list(range = c(0,255)),
    yaxis = list(range = c(0,255)),
    zaxis = list(range = c(0,255)),
    aspectmode = "cube"
    )
    )

    print(p)


    The above R code generates a simple cirlce in 3d, but set one of the wavelengths to a higher integer and then it gets more interesting.



    Sine/Cos functions are defined in terms of a unit circle, where $x^2 + y^2 = r^2$, so my function maps an angle to a some point in the set of points that is a fixed 2norm distance form the center.



    I don't like how the curves tend not to explore the corners of the cube so I want to try above concept based on a higher norm. For example, $x^3 + y^3 = r^3$. Is there a simple way of achieving this?
    I can do this for a single loop by parameterizing in terms of a dummy variable (t) and just walking along the curve based on a start location and gradient, but then I won't be able to fiddle with the phase/wavelength etc, or can I?







    share|cite|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm not even sure how to succinctly ask this question in the title, so let me explain.



      I occasionally find myself wanting to map a number to a color in RGB space. I usually do this by expressing a circle in 3d as a function of an angle. As an aid in designing this mapping, I decided to put together a shiny app that visualizes the line in RGB space. This started off as a plain old circle in 3d space, using trigonometric functions, but then I realized I can get some fairly crazy curves (and thus interesting color mappings) by fiddling with the phase, radius, wavelength etc.



      library(plotly)
      library(shiny)

      xPhase = 20
      yPhase = 120
      zPhase = 240
      xCenter = 127
      yCenter = 127
      zCenter = 127
      xWavelength = 1
      yWavelength = 1
      zWavelength = 1
      zRadRadius = 0
      xRadius = 100
      yRadius = 100
      zRadius = 100

      gcd = function(args)
      if (any(args <= 0))

      stop("All arguments to gcd must be positive")

      if (length(args) < 2)

      stop("Invalid number of arguments")

      a = args[1]
      b = args[2]
      r = a %% b
      if (r > 0)

      return(gcd(c(b,r,args[-c(1,2)])))

      else if (length(args) > 2)

      return(gcd(c(b,args[-c(1,2)])))

      else

      return(b)



      lcm = function(args)
      if (any(args <= 0))

      stop("All arguments to gcd must be positive")

      if (length(args) < 2)

      stop("Invalid number of arguments")

      g = gcd(args[1:2])
      m = prod(args[1:2])/g
      if (length(args)>2)

      return(lcm(c(m,args[-c(1,2)])))

      else

      return(m)



      maxTheta = lcm(c(xWavelength,yWavelength,zWavelength))*360
      theta = 0:maxTheta

      x = cos(((theta + xPhase) / xWavelength) / 180 * pi) * xRadius + xCenter
      y = cos(((theta + yPhase) / yWavelength) / 180 * pi) * yRadius + yCenter
      z = cos(((theta + zPhase) / zWavelength) / 180 * pi) * zRadius + zCenter
      colors = rgb(x, y, z, maxColorValue = 255)
      data = data.frame(theta = theta, x = x, y = y, z = z, colors = colors, avg = apply(cbind(x,y,z),1,mean))

      p <- plot_ly(data, x = ~x, y = ~y, z = ~z, colors = ~colors, type = 'scatter3d', mode = 'lines',
      opacity = 1, line = list(width = 6, reverscale = FALSE, color = ~colors)) %>%
      layout(
      scene = list(
      xaxis = list(range = c(0,255)),
      yaxis = list(range = c(0,255)),
      zaxis = list(range = c(0,255)),
      aspectmode = "cube"
      )
      )

      print(p)


      The above R code generates a simple cirlce in 3d, but set one of the wavelengths to a higher integer and then it gets more interesting.



      Sine/Cos functions are defined in terms of a unit circle, where $x^2 + y^2 = r^2$, so my function maps an angle to a some point in the set of points that is a fixed 2norm distance form the center.



      I don't like how the curves tend not to explore the corners of the cube so I want to try above concept based on a higher norm. For example, $x^3 + y^3 = r^3$. Is there a simple way of achieving this?
      I can do this for a single loop by parameterizing in terms of a dummy variable (t) and just walking along the curve based on a start location and gradient, but then I won't be able to fiddle with the phase/wavelength etc, or can I?







      share|cite|improve this question














      I'm not even sure how to succinctly ask this question in the title, so let me explain.



      I occasionally find myself wanting to map a number to a color in RGB space. I usually do this by expressing a circle in 3d as a function of an angle. As an aid in designing this mapping, I decided to put together a shiny app that visualizes the line in RGB space. This started off as a plain old circle in 3d space, using trigonometric functions, but then I realized I can get some fairly crazy curves (and thus interesting color mappings) by fiddling with the phase, radius, wavelength etc.



      library(plotly)
      library(shiny)

      xPhase = 20
      yPhase = 120
      zPhase = 240
      xCenter = 127
      yCenter = 127
      zCenter = 127
      xWavelength = 1
      yWavelength = 1
      zWavelength = 1
      zRadRadius = 0
      xRadius = 100
      yRadius = 100
      zRadius = 100

      gcd = function(args)
      if (any(args <= 0))

      stop("All arguments to gcd must be positive")

      if (length(args) < 2)

      stop("Invalid number of arguments")

      a = args[1]
      b = args[2]
      r = a %% b
      if (r > 0)

      return(gcd(c(b,r,args[-c(1,2)])))

      else if (length(args) > 2)

      return(gcd(c(b,args[-c(1,2)])))

      else

      return(b)



      lcm = function(args)
      if (any(args <= 0))

      stop("All arguments to gcd must be positive")

      if (length(args) < 2)

      stop("Invalid number of arguments")

      g = gcd(args[1:2])
      m = prod(args[1:2])/g
      if (length(args)>2)

      return(lcm(c(m,args[-c(1,2)])))

      else

      return(m)



      maxTheta = lcm(c(xWavelength,yWavelength,zWavelength))*360
      theta = 0:maxTheta

      x = cos(((theta + xPhase) / xWavelength) / 180 * pi) * xRadius + xCenter
      y = cos(((theta + yPhase) / yWavelength) / 180 * pi) * yRadius + yCenter
      z = cos(((theta + zPhase) / zWavelength) / 180 * pi) * zRadius + zCenter
      colors = rgb(x, y, z, maxColorValue = 255)
      data = data.frame(theta = theta, x = x, y = y, z = z, colors = colors, avg = apply(cbind(x,y,z),1,mean))

      p <- plot_ly(data, x = ~x, y = ~y, z = ~z, colors = ~colors, type = 'scatter3d', mode = 'lines',
      opacity = 1, line = list(width = 6, reverscale = FALSE, color = ~colors)) %>%
      layout(
      scene = list(
      xaxis = list(range = c(0,255)),
      yaxis = list(range = c(0,255)),
      zaxis = list(range = c(0,255)),
      aspectmode = "cube"
      )
      )

      print(p)


      The above R code generates a simple cirlce in 3d, but set one of the wavelengths to a higher integer and then it gets more interesting.



      Sine/Cos functions are defined in terms of a unit circle, where $x^2 + y^2 = r^2$, so my function maps an angle to a some point in the set of points that is a fixed 2norm distance form the center.



      I don't like how the curves tend not to explore the corners of the cube so I want to try above concept based on a higher norm. For example, $x^3 + y^3 = r^3$. Is there a simple way of achieving this?
      I can do this for a single loop by parameterizing in terms of a dummy variable (t) and just walking along the curve based on a start location and gradient, but then I won't be able to fiddle with the phase/wavelength etc, or can I?









      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Aug 27 at 9:42

























      asked Aug 26 at 12:53









      Chechy Levas

      16810




      16810

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "69"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2895013%2fhow-do-i-convert-a-polar-formula-for-a-circle-to-a-circle-based-on-a-higher-nor%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2895013%2fhow-do-i-convert-a-polar-formula-for-a-circle-to-a-circle-based-on-a-higher-nor%23new-answer', 'question_page');

          );

          Post as a guest













































































          這個網誌中的熱門文章

          How to combine Bézier curves to a surface?

          Mutual Information Always Non-negative

          Why am i infinitely getting the same tweet with the Twitter Search API?