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

  • Context: Graduate 
  • Thread starter Thread starter arpace
  • Start date Start date
  • Tags Tags
    Curve Sin
Click For Summary
SUMMARY

The discussion focuses on the discrepancies between the output of a Hermite curve algorithm and the sine function in ActionScript 3 (AS3) and JavaScript. The user provides control points for the Hermite curve and a function to calculate the y-coordinate at a given angle between 0 and 45 degrees. Despite implementing the algorithm correctly, the results do not match the expected output from the Math.sin() function, leading to speculation about potential floating-point errors or the need for further adjustments to align the results.

PREREQUISITES
  • Understanding of Hermite curves and their control points
  • Proficiency in ActionScript 3 and JavaScript programming
  • Familiarity with trigonometric functions, specifically sine
  • Knowledge of floating-point arithmetic and its implications in programming
NEXT STEPS
  • Investigate the mathematical properties of Hermite curves and their applications
  • Learn about floating-point precision issues in AS3 and JavaScript
  • Explore the differences between Hermite curves and sine functions in graphical representations
  • Examine techniques for normalizing points on a curve to match circular functions
USEFUL FOR

Mathematicians, software developers, and anyone involved in computer graphics or animation who seeks to understand the relationship between Hermite curves and trigonometric functions.

arpace
Messages
9
Reaction score
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
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()
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
12K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K