Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

some math in ruby

For general discussion related FlowStone

some math in ruby

Postby Nubeat7 » Sat Apr 02, 2016 1:18 am

i need to find out an angle between 2 lines
both start at centerpoint and thje zero line is fixed at 12 o'clock

here is what i have so far, but i really don't know how to go further
Attachments
circular_experiments.fsm
(1.13 KiB) Downloaded 989 times
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: some math in ruby

Postby RJHollins » Sat Apr 02, 2016 4:29 am

Hi NuBeat,

Don't know if this would be on any help ... but something I found in one of the toolboxes might give clue
Pie angle.fsm
(4.83 KiB) Downloaded 933 times
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: some math in ruby

Postby tulamide » Sat Apr 02, 2016 5:43 am

What you need is vector math (google for it for details). Here's a vector pad I made some time ago, that should help you a good deal:
http://www.dsprobotics.com/support/viewtopic.php?f=3&t=3900
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: some math in ruby

Postby martinvicanek » Sat Apr 02, 2016 5:59 am

Try angle = arctan2(x,y) or arctan2(y,x) depending on whether you measure against the x- or the y-axis.
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: some math in ruby

Postby Tronic » Sat Apr 02, 2016 8:39 am

angle = Math.atan2((@c[1] - y), (@c[0] - x)) :roll:
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: some math in ruby

Postby Tronic » Sat Apr 02, 2016 9:49 am

Code: Select all
angle = Math.atan2( (@c[1]-y), (@c[0]-x) )
offset = Math::PI/2.0 # 12 o'clock
radians = (angle+offset).modulo(2*Math::PI) - Math::PI
degress = (angle-offset).modulo(2*Math::PI) * (180/Math::PI)
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: some math in ruby

Postby tulamide » Sat Apr 02, 2016 12:30 pm

Did any of you both look at my Ruby example, whose link I posted? Because it's all in there. So, basically you're just repeating what is already there ;)

However, Nubeat, I want to point ypour attention to something important. Unlike something like distance, angle detection is always dependent on the point of view. From where to where you try to get the angle. That's always to consider. There are always two angles between two points, because angles are counted clockwise. So, if from a to b the angle is 120 degree, then from b to a it is 240 degree.

In my schematic that's made easy: Call the angle method always with that point first, from whose perspective you want to get the angle.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: some math in ruby

Postby Nubeat7 » Sat Apr 02, 2016 3:51 pm

thank you guys!

i'm still at work, but had the chance to try it , tronic's example works perfectly.. thank you!

but also your example, Tulamide, does exactly what i need, since i'm not very comfortable with all that circular calculations i will have a close look to your example, thanks for the link and sharing!
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: some math in ruby

Postby Tronic » Sat Apr 02, 2016 7:56 pm

@tulamide
hehe sorry,
I sometimes can not resist for an intellectual challenge :D
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: some math in ruby

Postby RJHollins » Sat Apr 02, 2016 8:41 pm

Everyone's post can help :mrgreen: I appreciate it.

Usually I don't have immediate need of angles, degrees, radians ... but it does come up when setting Knob swing parameters.

I always get confused by these settings for some reason. It seems the Knob and Dial design use 2 different references. I do get it to work ... but it gets a bit of a brain-tease. :lol:

Reading one of the posts here really helped to confirm the now obvious. [I don't make Knobs and dials all the time, so enough time passes that I forget the basics].

Anyway ... thanks for the Links, examples, and dialog 8-)
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm


Return to General

Who is online

Users browsing this forum: No registered users and 57 guests