e.normal to degrees in 360

About advanced scenes, and the Thyme scripting language used in Algodoo.

e.normal to degrees in 360

Postby fox11trot » Fri Nov 27, 2009 1:23 am

I just need a script to get the degrees of the angle in 360 degrees.

I keep searching for this but all i can find is how to get e.normal to degrees up to 180 and then goes to negative degrees.

Thank you :D
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: e.normal to degrees in 360

Postby standardtoaster » Fri Nov 27, 2009 1:41 am

I'm on my iPod right now, so this is off the top of my head.
Code: Select all
scene.my.rad2deg=(n)=>{n * math.pi/180}

Whatever you were using to get the angle to 180, e.normal(0) or e.normal(1) or a manipulation of them, use the variable I previously said. If you could post what you currently using that would be of great help.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: e.normal to degrees in 360

Postby fox11trot » Fri Nov 27, 2009 1:47 am

heres what i was using before

Code: Select all
{(math.acos(e.normal(0)) * (180 / math.pi)) > 90} ? {e.geom.anglen = (math.acos(e.normal(1)) * (180 / math.pi))} : {e.geom.anglen = (-(math.acos(e.normal(1)) * (180 / math.pi)))}; 
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: e.normal to degrees in 360

Postby standardtoaster » Fri Nov 27, 2009 1:49 am

Try using math.pi/180 instead of 180/math.pi
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: e.normal to degrees in 360

Postby fox11trot » Fri Nov 27, 2009 1:51 am

hmm that gives me some random decimal for the angle
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: e.normal to degrees in 360

Postby standardtoaster » Fri Nov 27, 2009 1:59 am

Sorry about that. Here it is, fixed, as far as I know.
Code: Select all
{(math.acos(e.normal(0)) * (180 / math.pi)) > 90} ? {e.geom.anglen = (math.acos(e.normal(1)) * (180 / math.pi))} : {e.geom.anglen = (180 + (math.acos(e.normal(1)) * (180 / math.pi)))}; 

How's that?
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: e.normal to degrees in 360

Postby fox11trot » Fri Nov 27, 2009 8:10 am

OK omg Thank YOU!
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: e.normal to degrees in 360

Postby Versieon » Fri Nov 27, 2009 8:19 pm

Actualy, it seems to be that that code doesn't go from 0 - 360, it goes from 0 - 180, and 360 - 181 in a circle. I think it should be this. just add a negative 1

Code: Select all
{(math.acos(e.normal(0)) * (180 / math.pi)) > 90} ? {e.geom.anglen = (math.acos(e.normal(1)) * (180 / math.pi))} : {e.geom.anglen = (180 + (math.acos((-1) * e.normal(1)) * (180 / math.pi)))};


That should work better.
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: e.normal to degrees in 360

Postby fox11trot » Sun Nov 29, 2009 8:54 pm

yeah i tried it and u were right

i will try versions code
THANK YOU
fox11trot
 
Posts: 62
Joined: Tue Sep 01, 2009 7:25 am

Re: e.normal to degrees in 360

Postby KarateBrot » Sun Nov 29, 2009 9:02 pm

Versieon wrote:Actualy, it seems to be that that code doesn't go from 0 - 360, it goes from 0 - 180, and 360 - 181 in a circle. I think it should be this. just add a negative 1

That should work better.


Why so complicated? :wtf:

Code: Select all
scene.my.angle = math.acos(e.normal(0)) * 180/math.pi ; e.normal(1) < 0 ? {scene.my.angle = 360 - scene.my.angle} : {}
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.normal to degrees in 360

Postby jessebax129 » Mon Jan 11, 2010 10:08 pm

standardtoaster wrote:I'm on my iPod right now, so this is off the top of my head.
Code: Select all
scene.my.rad2deg=(n)=>{n * math.pi/180}

Whatever you were using to get the angle to 180, e.normal(0) or e.normal(1) or a manipulation of them, use the variable I previously said. If you could post what you currently using that would be of great help.




BUT: what does the (n) in the script? what is is for ?


scene.my.rad2deg = (n) => {n*math.pi / 180} so i mean the n of
^
that one (the (n) i whas talking about


and what does e.normal mean in everything of the script? why is it so important
jessebax129
 
Posts: 34
Joined: Tue Jan 05, 2010 6:32 pm

Re: e.normal to degrees in 360

Postby standardtoaster » Mon Jan 11, 2010 10:28 pm

n is a parameter. You use it like this: scene.my.rad2deg(math.pi/4) e.normal is the normal of an object. For more information on normal go here.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: e.normal to degrees in 360

Postby KarateBrot » Mon Jan 11, 2010 10:40 pm

for n you put in the angle you want to convert from radians to degrees. n is just the variable for it.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.normal to degrees in 360

Postby jessebax129 » Tue Jan 12, 2010 6:53 pm

KarateBrot wrote:for n you put in the angle you want to convert from radians to degrees. n is just the variable for it.




can't you just say:

Code: Select all
angle1 = (n)=> {360} ??????
:clap: ANGLE1 IS THE VARIABLE THAT I USE FOR THIS :clap:
jessebax129
 
Posts: 34
Joined: Tue Jan 05, 2010 6:32 pm

Re: e.normal to degrees in 360

Postby standardtoaster » Tue Jan 12, 2010 7:18 pm

That would not work for this. You just made a function that says angle1(n) = 360! What Scene.my.rad2deg does is take n, which is the parameter, ie. the thing you replace it with, and then return the radians as degrees. Scene.my.rad2deg(Scene.my.angle1) will tell you what Scene.my.angle1 would be if it was in degrees.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: e.normal to degrees in 360

Postby KarateBrot » Tue Jan 12, 2010 7:48 pm

jessebax129 wrote:can't you just say:

Code: Select all
angle1 = (n)=> {360} ??????
:clap: ANGLE1 IS THE VARIABLE THAT I USE FOR THIS :clap:


Do you know something about mathematical functions? They work like functions in algodoo.

For example:
The mathematical notation is f(x) = x²
In Algodoo this would be scene.my.f = (x) => { x^2 }
- - - - -
And now if you want to let Algodoo calculate scene.my.f for any x you type in scene.my.f(x) where x is your desired value of which algodoo has to calculate the square from.

Mabe it's more clear if you know about this.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: e.normal to degrees in 360

Postby jessebax129 » Wed Jan 13, 2010 4:28 pm

okay but can i use instead of scene.my.rad2deg = (n) => {............} to-->> angle1= (n) => {......} ???
jessebax129
 
Posts: 34
Joined: Tue Jan 05, 2010 6:32 pm

Re: e.normal to degrees in 360

Postby standardtoaster » Wed Jan 13, 2010 4:40 pm

You can, although that would be another function. Angle1(n) would return something.
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm

Re: e.normal to degrees in 360

Postby KarateBrot » Wed Jan 13, 2010 7:17 pm

You can use any name you want. it's just a name. the function is the thing behind "angle1 =". but make sure to use custom variables! otherwise this doesn't work on other computers and only on your own one. so always make sure to put scene.my. in front of it

Instead of:
angle1 = ...

You have to use:

scene.my.angle1 = ...
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests