Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:41:36+00:00 2026-05-27T18:41:36+00:00

I’m attempting to draw a graph using Cubic Hermite Splines . I grabbed the

  • 0

I’m attempting to draw a graph using Cubic Hermite Splines. I grabbed the simple code to do so from this interpolation methods page.

Here is my code:

private float HermiteInterpolate(float y0, float y1, float y2, float y3, float mu)
{
    var mu2 = mu * mu;

    var a0 = -0.5f * y0 + 1.5f * y1 - 1.5f * y2 + 0.5f * y3;
    var a1 = y0 - 2.5f * y1 + 2f * y2 - 0.5f * y3;
    var a2 = -0.5f * y0 + 0.5f * y2;
    var a3 = y1;

    return (a0 * mu * mu2) + (a1 * mu2) + (a2 * mu) + a3;
}

With this data (y-values, from 0-1, x-values are distributed evenly from 0-21):

0, 0.09448819, 0.1102362, 0.1338583, 0.1811024, 0.2283465 ,0.3543307, 0.4645669, 0.480315, 0.480315, 0.527559, 0.527559, 0.527559, 0.527559, 0.527559, 0.527559, 0.6062992, 0.6377953, 0.6377953, 0.6377953, 0.7480315

And here is the result:

Hermite Graph

The problem is, at some areas of the graph, the line goes downward. Looking at the data, it never decreases. I don’t know if the algorithm is supposed to do this, but for what I am working on, I want the lines to never go downward (and if I was drawing the graph by hand, I would never make them point downward anyway).

So,

  • Is there something wrong with the graphing?
  • Is the algorithm supposed to do this? If so, is there one where this doesn’t happen?
  • I have tried cosine interpolation, but didn’t like how it turned out.

Here is the actual graphing function:

public void DrawGraph(IList<float> items)
{
    for (var x = 0; x < Width; x++)
    {
        var percentThrough = (float)x / (float)Width;
        var itemIndexRaw = items.Count * percentThrough;
        var itemIndex = (int)Math.Floor(itemIndexRaw);

        var item = items[itemIndex];
        var previousItem = (itemIndex - 1) < 0 ? item : items[itemIndex - 1];
        var nextItem = (itemIndex + 1) >= items.Count ? item : items[itemIndex + 1];
        var nextNextItem = (itemIndex + 2) >= items.Count ? nextItem : items[itemIndex + 2];

        var itemMu = FractionalPart(itemIndexRaw);

        var pointValue = HermiteInterpolate(previousItem, item, nextItem, nextNextItem, itemMu);

        WritePixel(x, (int)(pointValue * Height) - 1, (1 - FractionalPart(pointValue)), false);
        WritePixel(x, (int)(pointValue * Height), 1.0f, false);
        WritePixel(x, (int)(pointValue * Height) + 1, FractionalPart(pointValue), false);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:41:37+00:00Added an answer on May 27, 2026 at 6:41 pm

    This behavior is normal.

    Interpolation methods impose certain continuity conditions in order to give the appearance of a smooth curve. For Hermite interpolation, there is no condition that the interpolating curve through a sequence of increasing values must also be increasing everywhere, and so sometimes you get the effect you show here.

    There is something called monotone cubic interpolation which does what you want: if the data points are increasing, the interpolating curve will be increasing everywhere also.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.