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
10 posts
• Page 1 of 1
some math in ruby
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
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 990 times
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: some math in ruby
Hi NuBeat,
Don't know if this would be on any help ... but something I found in one of the toolboxes might give clue
Don't know if this would be on any help ... but something I found in one of the toolboxes might give clue
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: some math in ruby
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
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
Try angle = arctan2(x,y) or arctan2(y,x) depending on whether you measure against the x- or the y-axis.
-
martinvicanek - Posts: 1328
- Joined: Sat Jun 22, 2013 8:28 pm
Re: some math in ruby
angle = Math.atan2((@c[1] - y), (@c[0] - x))
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: some math in ruby
- 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
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.
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
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!
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!
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: some math in ruby
@tulamide
hehe sorry,
I sometimes can not resist for an intellectual challenge
hehe sorry,
I sometimes can not resist for an intellectual challenge
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: some math in ruby
Everyone's post can help 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.
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
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.
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
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 62 guests