Advanced Delphi

Moderators: None (Apply to moderate this forum)
Number of threads: 333
Number of posts: 743

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Maths function help Posted by Clintonb on 2 May 2011 at 10:06 AM
I've created an app that uses the maths function (i'm a first time user). The two functions i've created are to convert from x to y and then the reverse of y to x.

function xtoy(x:real;center:tpoint;rad:real):real;

var
answer:real;

begin;
answer:=x;
answer:=centerpoint.y-answer;
answer:=answer/(rad*0.5);
answer:=math.Power(2.718281828459045,answer);
answer:=math.ArcSin( (answer-1)/(answer+1) );
answer:=answer*180/3.141592654;

result:=answer;
end;

function ytox(y:double;center:tpoint;rad:double):double;

var
answer:double;
checkout:integer;
min,diff:real;

begin;
answer:=y;

answer:=answer*((22/7)/180);

answer:=math.LogN(2.718281828459045,(1+Sin(answer))/ (1-sin(answer)));
answer:=answer*0.5*rad;
answer:=centerpoint.y-answer;

result:=answer;
end;


These functions are the reverse of each other and technically, if you were to use them in xty(ytox(10,1,1),1,1) should return the answer 10 but when centerpoint and rad become larger in value, there is an increasing differnece between what i should get and what i do. ie ytox(10,100000,100000)=4 and xtoy(4,100000,100000)=21? Obviously they are approximately opposite but deviate at large values but i've looked at this 100 times and i can't see the error. If anything jumps out as obviously wrong, could you please drop me a message.

Thanks in advance
Clinton



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.