Back on the math ( slightly different focus)
Moderator: General Moderators
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Back on the math ( slightly different focus)
So have you ever been thinking.. man I need to calculate the distance between two points...how am I going to code that? Granted, I am over simplifying but do tell me what things you have tried to accomplish mathemtically in PHP or things that you weren't even able to but wanetd to. Let me know! I plan on beginning work on a math library for PHP . Since my main area of study right now is calculus and linear algebra I will probably start on htat front first but if anybody has some pressing needs or desires then let me know and I'll start work on those first. 
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Calculating the position of the sun (very very accuratley) based on geographical location, and time of year (to the second).... OUCH... I haven't done maths since A-Level (16-18 yo) but it was good fun to work on... and immensely complex - no kidding this was full-on hard-core maths I didn;t know anything about to start with. Other than that one-off project it's only been vaguely technical maths that I do all the time in programming with *fairly* poor mental arithmetic skills.... but hey... what are calculators for? 
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Code: Select all
class Point {
var $x;
var $y;
function Point($x, $y) {
$this->x = $x;
$this->y = $y;
}
function dist($p) {
return sqrt(pow($this->x - $p->x,2)+pow($this->y - $p->y,2));
}
function show() {
return '('.$this->x.','.$this->y.')';
}
}-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Well you asked "man I need to calculate the distance between two points...how am I going to code that? " That would be my answer, write a class to encapsulate "pointness", create two instances of Point, and ask one how far it is from the other.
I had this point class lying around as a example for some reason. Even have a test case:
I had this point class lying around as a example for some reason. Even have a test case:
Code: Select all
class PointTestCase extends UnitTestCase {
function TestPointDistance() {
$p1 = new Point(1,1);
$p2 = new Point(2,2);
$p3 = new Point(1,3);
$this->assertEqual(sqrt(2), $p1->dist($p2));
$this->assertEqual(2, $p1->dist($p3));
}
}-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
I think what Charles is trying to say is that he'd like to know what sort of problems with Maths people are having
Simple geometry is a given in any math's library, but are there any other areas of interest to folk?
Personally I think we need:
a) a maths book
b) an OOP structure
c) get kicking.
If we keep the classes small and tight, should be able to keep things organised as we move along to establishing an interface into the library.
Personally I think we need:
a) a maths book
b) an OOP structure
c) get kicking.
If we keep the classes small and tight, should be able to keep things organised as we move along to establishing an interface into the library.