﻿ Can Somone Please check my Maths are the same as my Code?
• September 28, 2023, 04:08:48 PM
• Welcome, Guest

Pages: [1]

### AuthorTopic: Can Somone Please check my Maths are the same as my Code?  (Read 2781 times)

0 Members and 1 Guest are viewing this topic.

#### Jyujinkai

• Global Moderator
• Frequent poster
• Karma: 1
• Offline
• Posts: 352
##### Can Somone Please check my Maths are the same as my Code?
« on: January 03, 2009, 08:38:55 AM »

Hi there... I have made a complex maths thing... and I am not sure if i am translating it into WME properly as it is going all wierd but on paper it works fine when i work it out with values....

Anyway here we go... In this I have shown the MATHS version followed by how i wrote the same thign in WME....

If you can please have a look and tell me if i translated the MATHS into WME script correctly.

Code: WME Script
1. // Lets find the X,Y of H.
2. var Xh;
3. var Yh;
4.
5. // Original Math:- D1 = sqrt((Xa - Xb)^2 + (Ya - Yb)^2)
6. var tmpXpow1 = (Xa-Xb);
7. var tmpXpow2 = Math.Pow(tmpXpow1,2);
8.
9. var tmpYpow1 = (Ya-Yb);
10. var tmpYpow2 = Math.Pow(tmpYpow1,2);
11.
12. var tmpD1 = tmpXpow2+ tmpYpow2;
13. var D1 = Math.Sqrt(tmpD1);
14.
15. // Original Math:- (Xm ,  Ym) = ((Xa + Xb) / 2 , (Ya + Yb) / 2)
16. var Xm = (Xa + Xb) / 2;
17. var Ym = (Ya + Yb) / 2;
18.
19. // Original Math:- g1 = (Ya - Yb) / (Xa - Xb)
20. var g1 = (Ya - Yb) / (Xa - Xb);
21.
22. // Original Math:- g2 = -1 / g1
23. var g2 = -1 / g1;
24.
25. // Original Math:- phi = atan(g2)
26. var phi = Math.Atan(g2);
27.
28. // Original Math:- D2 = D1 * tan(K) / 2
29. var tanK = Math.Tan(K);
30. var D2 = D1 * tanK / 2;
31.
32. // Original Math:- (Xh , Yh) = (Xm + D2 * cos(phi), Ym + D2 * sin(phi))
33. var cosPHI = Math.Cos(phi);
34. Xh = Xm + D2 * cosPHI;
35.
36. var sinPHI = Math.Sin(phi);
37. Yh = Ym + D2 * sinPHI;
38.
39.
40. function ArcData(Xa, Ya, Xb, Yb, Xh, Yh)
41. {
42. /*Original Math Xc = [(Ya - Yh)(Xb^2 + Yb^2) + (Yh - Yb)(Xa^2 + Ya^2) + (Yb - Ya)(Xh^2 + Yh^2)]
43.                                 -------------------------------------------------------------------------------
44.                                                         2*[Xb*Ya + Xa*Yh + Xh*Yb - Yb*Xa - Ya*Xh - Yh*Xb]                      */
45. var XbP = Math.Pow(Xb,2);
46. var YbP = Math.Pow(Yb,2);
47. var XaP = Math.Pow(Xa,2);
48. var YaP = Math.Pow(Ya,2);
49. var XhP = Math.Pow(Xh,2);
50. var YhP = Math.Pow(Yh,2);
51.
52. var Xc = ((Ya-Yh)*(XbP+YbP)+(Yh - Yb)*(XaP+YaP)+(Yb-Ya)*(XhP + YhP)) / 2*(Xb*Ya + Xa*Yh + Xh*Yb - Yb*Xa - Ya*Xh - Yh*Xb);
53. //Yc = [(Xa - Xh)(Yb^2 + Xb^2) + (Xh - Xb)(Ya^2 + Xa^2) + (Xb - Xa)(Yh^2 + Xh^2)]
54. var Yc = ((Xa-Xh)*(YbP+XbP)+(Xh - Xb)*(YaP+XaP)+(Xb-Xa)*(YhP + XhP)) / 2*(Yb*Xa + Ya*Xh + Yh*Xb - Xb*Ya - Xa*Yh - Xh*Yb);
55.
56. // Original Math:- r = sqrt((Xa - Xc)^2 + (Ya - Yc)^2)
57.
58. var r1 = (Xa-Xc);
59. var r2 = (Ya-Yc);
60. var r3 = Math.Pow(r1,2);
61. var r4 = Math.Pow(r2,2);
62. var R = Math.Pow((r3+r4),2);
63.
64. /*Start angle = angle between horizontal and the line joining C and A = atan2(Ya - Yc, Xa - Xc)
65. Finish angle = angle between horizontal and the line joining C and B = atan2(Yb - Yc, Xb - Xc)                          */
66.
67. var Sag1 = Ya - Yc;
68. var Sag2 = Xa - Xc;
69. var Eag1 = Yb - Yc;
70. var Eag2 = Xb - Xc;
71. var Sag = Math.Atan2(Sag1,Sag2);
72. var Eag = Math.Atan2(Eag1,Eag2);
73.
74.
75. /*4) any angle between the start angle and finish angle will give you a point along the arc, so you can use code like the following pseudo code to generate these points:
76.
77.   for each angle theta between the start angle and finish angle do the following
78.     calculate the x coordinate as Xp = Xc + r * cos(theta)
79.     calculate the y coordinate as Yp = Yc + r * sin(theta)
80.     output the point on the arc as (Xp,Yp)                                          */
81.
82. var CosAG = Math.Cos(Sag);
83. var SinAG = Math.Sin(Sag);
84. var Xp1 = Xc + R * CosAG;
85. var Yp1 = Yc + R * SinAG;
86.
87. var CosAG1 = Math.Sin(Eag);
88. var SinAG1 = Math.Sin(Eag);
89. var Xp2 = Xc + R * CosAG1;
90. var Yp2 = Yc + R * SinAG1;
Logged
<Antoine de Saint-Exupéry> In any thing at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away...
<Carl Sagan> If you want to make a apple pie from scratch. You must first... invent the universe
Pages: [1]

Page created in 0.024 seconds with 19 queries.