اقتباسلأفضل أثناء كتابة Specification ( المواصفات) لكل كلاس .. أن نلتزم بأن يكون الكود موجّه لجميع المبرمجين وليس مكتوب بطريقة لايفهمها الا مبرمجي السي بلس
نسيت هذه النقطه تماما
اقتباسلكن كنت أتمنى يوجد وصف ولو مختصر لبعض الدوال
ارجو وضع شرح و لو بسيط لنظام الملاحظات الذى سنتبعه لإنى لا اعرفه.
اقتباسبالنسبه للنوع Matrix و Vector سأضيفهم بعد الفجر.أتمنى تتنظر قليلاً أخ محمد .. حتى ننتهي من الكلاسات السابقة ، خلال 24 ساعة ان شاء الله .. ونعتمد مواصفاتها .
لقد جهزتهم من حوالى يومين و كل مره اوشك على وضعهم يغلبنى الإرهاق فأنام، و لكن اقتراح جيد اخى عبد الله و ذلك حتى نركز كل تفكيرنا فى الأنواع التى وضعناها و ننتهى منهم ثم نرى الجديد.
اقتباسمانظام الاحداثيات الذي سنتعامل معه
بالطبع نظام الإحداثى الديكارتى للأشكال ثنائية البعد، و لمن لا يعرفه ففيه Y تزيد لاعلى و تنقص لأسفل.
نحن الأن نتكلم عن الرياضيات و ليس الرسم. سيكون من الصعب استخدام نظام احداثيات الشاشه اثناء محاولة تضمين دوال كل نوع.
======================================================
حتى لا نقوم بالتنقل بين صفحات الموضوع بحثا عن الأنواع هذه هى النسخه الأخيره التى قمنا بتجهيزها و الموافقه عليها جميعا (بالإضافه لبعض الدوال الجديده)
ارجو المراجعه عليها حتى نتفق على النسخه الأخيره منها
1 - الفئه Math : وتحتوى على مجموعه من الدوال الرياضيه العامه.
[color= #0000ff;]class Math
[color= #000000;]{
[color= #0000ff;]public[color= #000000;]:
[color= #0000ff;]static [color= #0000ff;]float ln[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float log2[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float log10[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float exp[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float alog2[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float alog10[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float pow[color= #000000;]([color= #0000ff;]float base,[color= #0000ff;]float exp[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float root[color= #000000;]([color= #0000ff;]float base,[color= #0000ff;]float exp[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float sqrt[color= #000000;]([color= #0000ff;]float base[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float abs[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float floor[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float ceiling[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float sin[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float cos[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float tan[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float asin[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float acos[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float atan[color= #000000;]([color= #0000ff;]float x[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float RadToDeg[color= #000000;]([color= #0000ff;]float angle[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float DegToRad[color= #000000;]([color= #0000ff;]float angle[color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float PI[color= #000000;]([color= #000000;]);
[color= #0000ff;]static [color= #0000ff;]float E[color= #000000;]([color= #000000;]);
[color= #000000;]};2 - الفئه Point2D : و تمثل نقطه داخل نظام الإحداثيات الذى سيتم اتباعه (الديكارتى او الشاشه حسب ما سنحدد)
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename T[color= #000000;]>
[color= #0000ff;]class Point2D
[color= #000000;]{
[color= #0000ff;]public[color= #000000;]:
[color= #007f00;]// x is the x-axis
[color= #007f00;]// y is the y-axis
T x, y;
[color= #007f00;]// add fixed distance to current point axises
[color= #0000ff;]void Move [color= #000000;]( T distance [color= #000000;]);
[color= #007f00;]// add p1 point to p2 point and return new point of those
[color= #007f00;]// return Point2D object, otherwise false
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]static Point2D[color= #000000;]<S[color= #000000;]> Add [color= #000000;]( Point2D[color= #000000;]<S[color= #000000;]> p1, Point2D[color= #000000;]<S[color= #000000;]> p2 [color= #000000;]);
[color= #007f00;]// subtract p1 point from p2 point and return new point of those
[color= #007f00;]// return Point2D object, otherwise false
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]static Point2D[color= #000000;]<S[color= #000000;]> Subtract [color= #000000;]( Point2D[color= #000000;]<S[color= #000000;]> p1, Point2D[color= #000000;]<S[color= #000000;]> p2 [color= #000000;]);
[color= #0000ff;]bool equal [color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Point2D[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #0000ff;]bool Notequal[color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Point2D[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #000000;]};3 - الفئه Line2D : و تمثل خط مستقيم داخل نظام الإحداثيات
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename T[color= #000000;]>
[color= #0000ff;]class Line2D
[color= #000000;]{
[color= #0000ff;]public[color= #000000;]:
[color= #007f00;]// start is the start point of line
[color= #007f00;]// end is the end point of line
Point2D[color= #000000;]<T[color= #000000;]> start, end;
[color= #007f00;]// check if passed point fall in current line
[color= #007f00;]// return true is it is, false otherwise
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsPointInLine[color= #000000;]( Point2D[color= #000000;]<S[color= #000000;]> p[color= #000000;]);
[color= #007f00;]// check if passed line is contained in current line
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsLineInMe[color= #000000;]( Line2D[color= #000000;]<S[color= #000000;]> l[color= #000000;]);
[color= #007f00;]// get line center point
[color= #007f00;]// in physics called center of gravity
[color= #007f00;]// return Point2D object, otherwise false
Point2D[color= #000000;]<T[color= #000000;]> getCenterPoint[color= #000000;]([color= #000000;]);
[color= #007f00;]// get line length
[color= #0000ff;]float getLineLenght[color= #000000;]([color= #000000;]);
[color= #007f00;]// increase line length by value
[color= #0000ff;]void Increase[color= #000000;](T value[color= #000000;]);
[color= #007f00;]// decrease line length by value
[color= #0000ff;]void Decrease[color= #000000;](T value[color= #000000;]);
[color= #007f00;]// move start point of line to new position
[color= #0000ff;]void Move [color= #000000;]( Point2D[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #007f00;]// get current line slop
[color= #0000ff;]float getLineSlope[color= #000000;]([color= #000000;]);
[color= #007f00;]// is passed line is perpendicular to current line
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]bool IsPerpendicular[color= #000000;]( Line2D[color= #000000;]<T[color= #000000;]> l [color= #000000;]);
[color= #007f00;]// get point that current line and passed line are perpendicular in
[color= #007f00;]// return point object if exist, null otherwise
Point2D[color= #000000;]<T[color= #000000;]> getPerpendicularPoint[color= #000000;]( Line2D[color= #000000;]<T[color= #000000;]> l [color= #000000;]);
[color= #007f00;]// get point that current line and passed line and intersect in
[color= #007f00;]// return point object if exist, null otherwise
Point2D[color= #000000;]<T[color= #000000;]> getIntersectPoint [color= #000000;]( Line2D[color= #000000;]<T[color= #000000;]> l [color= #000000;]);
[color= #007f00;]// add l1 line to l2 line and return the sum
[color= #007f00;]// return line object, otherwise null
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]static Line2D[color= #000000;]<S[color= #000000;]> Add [color= #000000;]( Line2D[color= #000000;]<S[color= #000000;]> l1, Line2D[color= #000000;]<S[color= #000000;]> l2 [color= #000000;]);
[color= #007f00;]// subtract l1 line from l2 line and return the difference
[color= #007f00;]// return line object, otherwise null
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]static Line2D[color= #000000;]<S[color= #000000;]> Subtract [color= #000000;]( Line2D[color= #000000;]<S[color= #000000;]> l1, Line2D[color= #000000;]<S[color= #000000;]> l2 [color= #000000;]);
[color= #0000ff;]bool equal [color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Line2D[color= #000000;]<T[color= #000000;]> l [color= #000000;]);
[color= #0000ff;]bool Notequal[color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Line2D[color= #000000;]<T[color= #000000;]> l [color= #000000;]);
[color= #000000;]};3 - الفئه Rectangle : و تمثل مربع او مستطيل داخل نظام الإحداثيات
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename T[color= #000000;]>
[color= #0000ff;]class Rectangle
[color= #000000;]{
[color= #0000ff;]public[color= #000000;]:
[color= #007f00;]// rectangle points
Point2D[color= #000000;]<T[color= #000000;]> top, bottom, left, right;
[color= #007f00;]// check if passed point fall in current rectangle
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsPointInRect [color= #000000;]( Point2D[color= #000000;]<S[color= #000000;]> p[color= #000000;]);
[color= #007f00;]// check if passed line fall in current rectangle
[color= #007f00;]// if the line points is two of rectangle points the function will return true
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsLineInRect [color= #000000;]( Line2D[color= #000000;]<S[color= #000000;]> l[color= #000000;]);
[color= #007f00;]// get rectangle center point
[color= #007f00;]// in physics called center of gravity
[color= #007f00;]// return Point2D object, otherwise false
Point2D[color= #000000;]<T[color= #000000;]> getCenterPoint[color= #000000;]([color= #000000;]);
[color= #007f00;]// return rectangle absloute height
[color= #0000ff;]float getHeight[color= #000000;]([color= #000000;]);
[color= #007f00;]// return rectangle absloute width
[color= #0000ff;]float getWidth[color= #000000;]([color= #000000;]);
[color= #007f00;]// is current rectangle is valid rectangle
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]bool IsValid[color= #000000;]([color= #000000;]);
[color= #007f00;]// get circle that current rectangle points are fall in its edge
[color= #007f00;]// in other word circle the our rectangle will fall in
[color= #007f00;]// remember that circle is always a circle not an ellipse so if the rectangle is
[color= #007f00;]// not square the returned circle will contained the rectangle but the rectangle
[color= #007f00;]// points may not be in circle edge.
[color= #007f00;]//
[color= #007f00;]// return circle object, null otherwise
Circle[color= #000000;]<T[color= #000000;]> getBoundCircle[color= #000000;]([color= #000000;]);
[color= #0000ff;]bool equal [color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Rectangle[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #0000ff;]bool Notequal[color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Rectangle[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #000000;]};4 - الفئه Circle : و تمثل دائره داخل نظام الإحداثيات
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename T[color= #000000;]>
[color= #0000ff;]class Circle
[color= #000000;]{
[color= #0000ff;]public[color= #000000;]:
[color= #007f00;]// center point of circle
[color= #007f00;]// also it is the center of gravity
[color= #007f00;]// because this type represent a perfect circle
Point2D[color= #000000;]<T[color= #000000;]> center;
[color= #007f00;]// circle radius
T Radius;
[color= #007f00;]// check if passed point is fall in current circle (circle edges are part of circle)
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsPointInCircle[color= #000000;]( Point2D[color= #000000;]<S[color= #000000;]> p [color= #000000;]);
[color= #007f00;]// check if passed line touch the circle edge in one point
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsLineTangent [color= #000000;]( Line2D[color= #000000;]<S[color= #000000;]> l [color= #000000;]);
[color= #007f00;]// check if passed line is intersect current circle in any point
[color= #007f00;]// return true if it is, false otherwise
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsLineIntersect [color= #000000;]( Line2D[color= #000000;]<S[color= #000000;]> l [color= #000000;]);
[color= #007f00;]// get intersect points if intersection exist
[color= #007f00;]// return array of 2 or 1 point(s) depend on intersection
[color= #007f00;]// otherwise null array
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
Point2D[color= #000000;]<S[color= #000000;]>[color= #000000;][[color= #000000;]] getIntersectPoint [color= #000000;]( Line2D[color= #000000;]<S[color= #000000;]> l [color= #000000;]);
[color= #007f00;]// return circle circumference
[color= #0000ff;]float getCircumference[color= #000000;]([color= #000000;]);
[color= #007f00;]// return circle area
[color= #0000ff;]float getArea[color= #000000;]([color= #000000;]);
[color= #007f00;]// get rectangle that contains current circle
[color= #007f00;]// because of the circle is always a prefect
[color= #007f00;]// circle that output object always a square
[color= #007f00;]//
[color= #007f00;]// return rectangle object, null otherwise
Rectangle[color= #000000;]<T[color= #000000;]> getBoundRect[color= #000000;]([color= #000000;]);
[color= #0000ff;]bool equal [color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Circle[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #0000ff;]bool Notequal[color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Circle[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #000000;]};5 - النوع Triangle : و هو يمثل مثلث داخل نظام الإحداثيات
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename T[color= #000000;]>
[color= #0000ff;]class Triangle
[color= #000000;]{
[color= #0000ff;]public[color= #000000;]:
[color= #007f00;]// triangle points
Point2D[color= #000000;]<T[color= #000000;]> p1, p2, p3;
[color= #007f00;]// get current triangle area
T getArea[color= #000000;]([color= #000000;]);
[color= #007f00;]// check if passed point is fall in current triangle
[color= #007f00;]// return true if it is, otherwise false
[color= #0000ff;]template [color= #000000;]<[color= #0000ff;]typename S[color= #000000;]>
[color= #0000ff;]bool IsPointInTringle[color= #000000;]( Point2D[color= #000000;]<S[color= #000000;]> p[color= #000000;]) const;
[color= #007f00;]// get Triangle center point
[color= #007f00;]// in physics called center of gravity
[color= #007f00;]// return Point2D object, otherwise false
Point2D[color= #000000;]<T[color= #000000;]> getCenterPoint[color= #000000;]([color= #000000;]);
[color= #007f00;]// get angle between two lines of current triangle
[color= #007f00;]// pass triangle points in various way to get your desire angle
[color= #007f00;]// return the angle in success, otherwise -1 if faild
[color= #0000ff;]float getAngleBetween [color= #000000;]( Point2D[color= #000000;]<T[color= #000000;]> line1_End_point, Point2D[color= #000000;]<T[color= #000000;]> Line2_End_point,
Point2D[color= #000000;]<T[color= #000000;]> intersect_point [color= #000000;]);
[color= #007f00;]// check if current triangle is valid triangle
[color= #007f00;]// return true if it is, otherwise false
[color= #0000ff;]bool IsValid[color= #000000;]([color= #000000;]);
[color= #007f00;]// get rectangle that contain current triangle
[color= #007f00;]// return rectangle object, otherwise null
Rectangle[color= #000000;]<T[color= #000000;]> getBoundRect[color= #000000;]([color= #000000;]);
[color= #007f00;]// get circle that contain current triangle
[color= #007f00;]// return circle object, otherwise null
Circle[color= #000000;]<T[color= #000000;]> getBoundCircle[color= #000000;]([color= #000000;]) const;
[color= #0000ff;]bool equal [color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Triangle[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #0000ff;]bool Notequal[color= #000000;]( [color= #000000;][IN, BYREF[color= #000000;]] Triangle[color= #000000;]<T[color= #000000;]> p [color= #000000;]);
[color= #000000;]};و الله ولى التوفيق
تم تعديل هذه المشاركة بواسطة Muhammad alaa في 29 سبتمبر 2009 في 19:40
مدونتي: C++ Tips and Tricks

