A parametric view of love

If you tell my wife that she's married to a statistical geek, she'll nod knowingly. She is used to hearing sweet words of affection such as

You are more beautiful than Euler's identity.
My love for you is like the exponential function: increasing, unbounded, and transcendental.

But those are ordinary, everyday sentiments. For Valentine's Day, I want to do something really special, such as formulating a parametric expression whose image is heart-shaped. If you haven't gotten anything sweet for your special someone, you too can use SAS/IML Studio to create the following image!

Modify the program to create your own personal message. My personal message to my wife is "I love you."

/** Valentine's Day heart. Rick Wicklin: blogs.sas.com/content/iml **/
/** Parametrize in polar coordinates h(t) = (r(t), theta(t)) **/
Pi = constant("Pi");
t = do(0, 2*Pi, 0.01*Pi/4)`;
r = 2 - 2*sin(t) + sin(t)#sqrt(abs(cos(t))) / (sin(t)+1.4);
/** Convert to Euclidean coordinates for plotting **/
x = r#cos(t);
y = r#sin(t);
/** Use SAS/IML Studio to produce the image **/
declare DataObject dobj;
dobj = DataObject.Create("Valentine", {"x" "y"}, x||y );
dobj.AddVar("const", j(nrow(t),1));
dobj.SetMarkerFillColor(OBS_ALL, RED);
declare PolygonPlot p;
p = PolygonPlot.Create(dobj, "x", "y", "const", true);
"r = 2 - 2*sin(t) + sin(t)*sqrt(|cos(t)|) / (sin(t)+1.4)");
tags: Just for Fun, SAS/IML Studio


  1. Thea Sinclair
    Posted February 14, 2011 at 8:09 am | Permalink

    While I did not understand the math, the sentiment and image was great. Your wife is a lucky woman.

  2. Jiangtang Hu
    Posted February 14, 2011 at 8:38 pm | Permalink

    Hi Rick,

    See the implementation of

    17 x^2 - 16|x|y + 17 y^2 =225

    in wolframalpha:

    Recently I use wolframalpha heavily. Wonderful tool.

  3. Rick Wicklin
    Posted February 15, 2011 at 9:13 am | Permalink

    Yes, that’s a good one!

    Your solution implicitly defines the curve as the level set of a surface, whereas mine is a parameterized curve. I wanted my heart to have sharp points at the middle and bottom of the heart. This is easier to do with a parametric curve than with an implicitly defined curve.

    Contouring algorithms often incorrectly represent the level set of a surface when the surface is tangent to the cutting plane. A classic example is the level set (x-alpha)^2-(y-beta)^2=0, which is supposed to be two lines that intersect at (alpha, beta). Contouring algorithms often represent this level set as two almost-touching hyperbolas.

    Notice in your example that the implicit curve as computed by Wolfram Alpha is "rounded" at (0, +/-15/sqrt(17)), whereas a correct representation of the curve would be "pointed" there.

  4. Posted February 14, 2012 at 11:13 am | Permalink

    Well .. I'm not much of a math person ... but I read this on a bathroom stall at a rest stop between Kentucky and Tennessee in fourth grade - and it's still good! Plus I'm sure of the math.

    2 lovers
    + 2 gether

    I read some other things that I won't share. But there are a lot of cheatin' boyfriends and little daVincis with magic markers out there! I'm just saying. :-)

2 Trackbacks

  1. By Belated code - SAS Users Groups on February 15, 2013 at 8:10 am

    [...] parameterization.  If my Valentine doesn't get you out of the dog house, read his post - A parametric view of love. tags: Friday's Innovation Inspiration Bookmark on Delicious Digg this post Recommend on Facebook [...]

  2. By Binary heart in SAS - The DO Loop on February 18, 2015 at 9:41 am

    […] years later, I used an equation in polar coordinates to draw a heart in SAS as a Valentine's Day gift to my wife. This year I thought it would be fun to combine these […]

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>