Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 8th, 2013, 07:55 PM
birdmw birdmw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 birdmw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 25 sec
Reputation Power: 0
Wink Vector object collision

Background:
We have a robot, we are using a servo with a parallax ir sensor mounted on top which sweeps 180 degrees and populates an array with the range it sees on a microcontroller. This array of ranges containes enough data to extract left and right edges of object in the room. I want to make a simulation using pygame that will simulate data so that hypobots (if you don't know what this is its just statistical hypothetical robot positions) can match to it.

Python: (using library pygame)
I want to make an array. (Simulated on a virtual map)
The array will hold one value per degree from 0 to 180
The value it holds is the distance vector to the object in the corresponding direction
The vector should be of length equal to the distance from the origin (later to be a variable location) to the first object it sees at a respective angle.

For example, if there is an object of width 3, And is in front of us, we will see an array of 9,9,9,9,9,1,1,1,9,9,9,9,9,9

The 1s are the near distance if the object, the 9's are the distant background

The core of it:
How should I go about drawing a vector that terminates as soon as it hits on object?

-communities like yours are a godsend to people like me, thank you so much for taking the time to go down this path with me please ask any questions because I know there are many losses in communication between electrical and software engineering.

Reply With Quote
  #2  
Old January 9th, 2013, 08:32 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,460 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 56 m 42 sec
Reputation Power: 403
Please reconsider.
Code:
...
                                              ###################################
                                                #################################
                                                  ###############################
                                                    #############################
                                                      ###########################
                                                        #########################
                                                         ########################
A flat wall has distance                                   ######################
                                                            #####################
measured_distance * cosine(angle)                             ###################
                                                               ##################
                                                                #################
                                                                 ################
                                                                  ###############
                                                                   ##############
                                                                    #############
Robot at the X                                                    ###############
The walls are                                                ####################
not flat.                                              ##########################
                                                  ###############################
                                            #####################################
                                       ##########################################
                                 ################################################
                            #####################################################
                      ###########################################################
                 ##########              ########################################
           ################  Golem        #######################################
        ###################  obscured        ####################################
X        ##################  here              ##################################
        ###################                      ################################
           ######################################################################
                 ################################################################
                      ###########################################################
                            #####################################################
                                 ################################################
                                       ##########################################
                                            #####################################
                                                  ###############################
                                                       ##########################
                                                             ####################
                                                                  ###############
                                                                    #############
                                                                   ##############
                                                                  ###############
                                                                 ################
                                                                #################
                                                               ##################
                                                              ###################
                                                            #####################
                                                           ######################
                                                         ########################
                                                        #########################
                                                      ###########################
                                                    #############################
                                                  ###############################
                                                #################################
                                              ###################################
                                           ######################################
                                        #########              ##################
                                     ############  Au           #################
                                 ################              ##################
                             ####################################################
                        #########################################################
                 ################################################################
 ################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################
Computed with j software.
Code:
TAU=: 2p1   NB.  Pi is wrong.   http://laughingsquid.com/pi-is-wrong/
angle=: 12&o.
deg=: (360 % TAU) * angle
mag=: 10&o.

A=:>|:(%&2 1x@(1 0x&+))&.>{;~(%~ i:)40
B=:j./"1 A
C=:0.9 < mag B
C=: C (+. (0.1 < mag) *. (_20&< *. <&20)@:deg) B
C { ' #'
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 9th, 2013, 11:31 AM
birdmw birdmw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 birdmw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 25 sec
Reputation Power: 0
Yes exactly! b49P23TIvg

Quote:
Originally Posted by b49P23TIvg
Please reconsider.
Code:
...
                                              ###################################
                                                #################################
                                                  ###############################
                                                    #############################
                                                      ###########################
                                                        #########################
                                                         ########################
A flat wall has distance                                   ######################
                                                            #####################
measured_distance * cosine(angle)                             ###################
                                                               ##################
                                                                #################
                                                                 ################
                                                                  ###############
                                                                   ##############
                                                                    #############
Robot at the X                                                    ###############
The walls are                                                ####################
not flat.                                              ##########################
                                                  ###############################
                                            #####################################
                                       ##########################################
                                 ################################################
                            #####################################################
                      ###########################################################
                 ##########              ########################################
           ################  Golem        #######################################
        ###################  obscured        ####################################
X        ##################  here              ##################################
        ###################                      ################################
           ######################################################################
                 ################################################################
                      ###########################################################
                            #####################################################
                                 ################################################
                                       ##########################################
                                            #####################################
                                                  ###############################
                                                       ##########################
                                                             ####################
                                                                  ###############
                                                                    #############
                                                                   ##############
                                                                  ###############
                                                                 ################
                                                                #################
                                                               ##################
                                                              ###################
                                                            #####################
                                                           ######################
                                                         ########################
                                                        #########################
                                                      ###########################
                                                    #############################
                                                  ###############################
                                                #################################
                                              ###################################
                                           ######################################
                                        #########              ##################
                                     ############  Au           #################
                                 ################              ##################
                             ####################################################
                        #########################################################
                 ################################################################
 ################################################################################
#################################################################################
#################################################################################
#################################################################################
#################################################################################
Computed with j software.
Code:
TAU=: 2p1   NB.  Pi is wrong.   http://laughingsquid.com/pi-is-wrong/
angle=: 12&o.
deg=: (360 % TAU) * angle
mag=: 10&o.

A=:>|:(%&2 1x@(1 0x&+))&.>{;~(%~ i:)40
B=:j./"1 A
C=:0.9 < mag B
C=: C (+. (0.1 < mag) *. (_20&< *. <&20)@:deg) B
C { ' #'

What a great idea!
Sometimes a picture is worth a thousand words....

Here is a to-scale, on the actual-board picture of precisely what I want my python simulation to do.


http://imageshack.us/photo/my-images/690/examplexm.jpg/

URL


The green box is the robot
the downed trees are below the radar and hence invisible
the blue lines are the vectors I wish to draw.

I would like the simulation to allow me to drop the bot down anywhere with a click, and then the blue lines are generated.

Reply With Quote
  #4  
Old January 9th, 2013, 12:26 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,460 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 56 m 42 sec
Reputation Power: 403
I would use a line drawing algorithm to find the far end of the line. From your drawing I imagine an array specifying surface height at each point in the grid.
Say your IR distance gauge is at height 7, the algorithm would search along a direction using the line drawing algorithm until it found a grid entry greater than 6. It looks like the topology grid can be much much coarser than the screen resolution. You might not need a particularly great implementation of the line algorithm.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Vector object collision

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap