Math expressions

For questions about using Classic.

Post » Sun Apr 11, 2010 6:05 pm

Where can I find the math that's being uses behind the system math expressions? I need to convert a few of them to work with my 3D coordinates system like distance between or w/e (those expressions that use xy only).

And 5 point lerp would be nice for half circle math so I don't have to toy with 5 lerps together to make a simple half circle or w/e for my collisions.
B
2
S
2
G
4
Posts: 259
Reputation: 1,968

Post » Sun Apr 11, 2010 7:05 pm

Make functions for your needs with the Function object?
B
16
S
8
G
4
Posts: 136
Reputation: 3,144

Post » Sun Apr 11, 2010 7:44 pm

[url:235kwe4m]http://sourceforge.net/apps/mediawiki/construct/index.php?title=System_Expressions[/url:235kwe4m]

Might want to take a look at cubic()
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sun Apr 11, 2010 9:07 pm

I'm sorry if I'm not clear, I wanted the real math for those expressions as if it was written down on pen and paper & how it was written with C++ so I can do a better job of converting. [quote="newt":1auke468]Might want to take a look at cubic()[/quote:1auke468]What about the 5th value? cubic abcd cubic bcde will do fine enough. thx
B
2
S
2
G
4
Posts: 259
Reputation: 1,968

Post » Sun Apr 11, 2010 9:42 pm

This should be of some use.
[url:3hgpkdoa]http://www.scirra.com/forum/viewtopic.php?f=17&t=4416#p35336[/url:3hgpkdoa]
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sun Apr 11, 2010 10:33 pm

You could also try looking at the implementation of the system expressions in System.cpp:

http://construct.svn.sourceforge.net/vi ... iew=markup

The ExpRoutineTable array at line 436 maps the expression string (eg. "lerp") to the routine (&SystemObject::eLerp) - if you then search for SystemObject::eLerp (without ampersand) you'll find the implementation:

[code:1y4dyv82] 3887 long SystemObject::eLerp(LPVAL theParams, ExpReturn& ret)
3888 {
3889 // Calculate linear interpolation:
3890 // lerp(a, b, x) = a + x(b - a)
3891 double a = theParams[0].GetDouble();
3892 double b = theParams[1].GetDouble();
3893 double x = theParams[2].GetDouble();
3894
3895 return ret = Lerp(a, b, x);
3896 }
[/code:1y4dyv82]

You can use that to find the implementation of any system expression. Does that help?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,528

Post » Mon Apr 12, 2010 11:10 pm

[quote="manontherun":2tp8nhj5]Where can I find the math that's being uses behind the system math expressions? I need to convert a few of them to work with my 3D coordinates system like distance between or w/e (those expressions that use xy only).

And 5 point lerp would be nice for half circle math so I don't have to toy with 5 lerps together to make a simple half circle or w/e for my collisions.[/quote:2tp8nhj5]

distance can work with any two dimensions, x,y x,z y,z etc.

3D distance is just: sqrt(?X^2+?Y^2+?Z^2)

angle(,,,,) doesnt need to be 3d.

what excactly is half circle math, and why do you need beziers to draw one? sin&cos is much better suited, and infact its extremely faster work wise and power wise. what are you trying to do because i cant help but think your making things harder for yourself the way your going about things right now
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Tue Apr 13, 2010 6:08 pm

[quote="Ashley":2ka6ao4k]Does that help?[/quote:2ka6ao4k]Yes, it does. Thank you.

@ QuaziGNRLnose I might send a PM regarding some of your questions.

I have a question. What uses more CPU? Adding abs(x1 - x2) + (repeat for y,z) or using the square root?
B
2
S
2
G
4
Posts: 259
Reputation: 1,968

Post » Wed Apr 14, 2010 12:54 am

[quote="manontherun":3c2m1ljz]I have a question. What uses more CPU? Adding abs(x1 - x2) + (repeat for y,z) or using the square root?[/quote:3c2m1ljz]
The square root calculation, definitely. Finding the square root of a number requires the use of multiplication and division, both of which are slower than addition and subtraction.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Wed Apr 14, 2010 1:01 pm

In the context of Construct, the difference between these two calculations is negligable (although linkman is right that the square root is technically more intensive). The overhead of the events probably measures 100x or 1000x the performance difference between two such low level functions. The only thing which matters is: is it fast enough?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,528

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests