What is causing the discrepancy between the Hermite curve and the sine function?

  • Thread starter arpace
  • Start date
  • Tags
    Curve Sin
In summary, the conversation discussed a Hermite curve with control points and an algorithm to find points on the curve at a given degree. The code in AS3 and Javascript was shown and compared to the standard Math.sin() function. The issue of floating point error was brought up and a helpful image was shared. It was discovered that dividing the resultant point's distance was necessary to get a result on the circle, but it still did not match the Math.sin() function. Further modifications would be needed to achieve the same result.
  • #1
arpace
9
0
So I have a Hermite curve with the control points:

//point# (x,y):

p0 (1,0)
p1 (1,(Math.sqrt(2)-1))
p2 (Math.sqrt(0.5), Math.sqrt(0.5))

I also have a very basic algorithm to find the point on the locus at a given degree between 0 and 45 degrees using the control points. I could extend it easily to 360, but I will wait to do so until I figure out what is going on.

AS3
Code:
//modify the degree
var degree:Number = 22.5;//modify this
function yAtAngle0to45(deg:Number):Number {
	if (deg < 0 || deg > 45) {
		trace('please keep it between 0 and 45 for now');
		return -2;//if -2 is returned, you know it is out of possible bounds
	}
	/*
	obviously if this was in a real math class, 
	p1y would be stored outside the function and 
	there would be error checking/handling code
	*/
	var p1Y:Number = Math.SQRT2 - 1;
	var degDivBy45:Number = deg / 45;
	var line0Y:Number =(p1Y)*degDivBy45;//point on line 0
	var line1Y:Number = p1Y + (Math.SQRT1_2 - p1Y)*degDivBy45;//point on line 1
	return (line0Y + (line1Y-line0Y)*degDivBy45);
}

trace( "my code:  " + yAtAngle0to45(degree) + "\nstandard: " + Math.sin(degree*Math.PI/180));

Javascript
Code:
//modify the degree
var degree = 4;//modify this

function yAtAngle0to45(deg){
	if (typeof deg != 'number') {
		return Number.NaN;
	}
	if (deg < 0 || deg > 45) {
		trace('please keep it between 0 and 45 for now');
		return -2;//if -2 is returned, you know it is out of possible bounds
	}
	/*
	obviously if this was in a real math class, 
	p1y would be stored outside the function and 
	there would be error checking/handling code
	*/
	var p1Y = Math.SQRT2 - 1;
	var degDivBy45 = deg / 45;
	var line0Y=(p1Y)*degDivBy45;//point on line 0
	var line1Y = p1Y + (Math.SQRT1_2 - p1Y)*degDivBy45;//point on line 1
	return (line0Y + (line1Y-line0Y)*degDivBy45);
}

alert( "my code: " + yAtAngle0to45(degree) + "\nstandard: " + Math.sin(degree*Math.PI/180));

if you run the code, you will see why I am having problems.

What is going on? I am assuming I overlooked something. I thought it might be due to floating point error, but although there is some rounding error, it doesn't seem to be the issue.

Below is an image I made to help myself with the concept.
[PLAIN]http://sphotos.ak.fbcdn.net/hphotos-ak-snc4/hs1384.snc4/163638_10100121877154282_28122817_59279302_5323393_n.jpg
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
figured out that you need to divide the resultant point's distance to get it a result that is on the circle; yet, even so, it doesn't yield the same result, and would take slight modification to get the same result as Math.sin()
 

Related to What is causing the discrepancy between the Hermite curve and the sine function?

What is a Hermite curve and how does it differ from a sine curve?

A Hermite curve is a type of mathematical function that is often used in computer graphics and animation to define the shape of a curve. It is defined by a set of control points and tangent vectors, which allow for more precise control over the shape of the curve. In contrast, a sine curve is a basic trigonometric function that is defined by a single amplitude and frequency, and is used to model periodic phenomena.

What are the advantages of using a Hermite curve over a sine curve?

One of the main advantages of using a Hermite curve is its ability to accurately represent complex curves and shapes. By using control points and tangent vectors, a Hermite curve can be manipulated to closely fit the desired shape, whereas a sine curve is limited by its basic shape. Additionally, Hermite curves can be used to create smooth transitions between curves, making them ideal for animation and computer graphics.

Can Hermite curves be used in real-life applications?

Yes, Hermite curves have a wide range of practical applications. They are commonly used in computer graphics, animation, and video game development to create smooth and realistic curves and shapes. Hermite curves are also used in engineering and physics, such as in the design of roller coaster tracks and the modeling of fluid dynamics.

Are Hermite curves difficult to work with?

While understanding the mathematical principles behind Hermite curves may be challenging, there are many software tools available that make working with Hermite curves relatively easy. These tools allow for interactive manipulation of control points and tangent vectors, making it possible for non-mathematicians to use Hermite curves in their work.

Are there any limitations to using Hermite curves?

Like any mathematical function, Hermite curves have limitations. They are not suitable for modeling all types of curves, especially those with sharp corners or discontinuities. Additionally, creating a Hermite curve that accurately represents a given shape may require a significant amount of control points and tangent vectors, which can be time-consuming to define and manipulate.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
Replies
4
Views
4K
  • Programming and Computer Science
Replies
2
Views
9K
  • Programming and Computer Science
Replies
4
Views
5K
  • Introductory Physics Homework Help
Replies
1
Views
2K
Back
Top