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

  • Thread starter Thread starter arpace
  • Start date Start date
  • Tags Tags
    Curve Sin
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()
 
Back
Top