Drawing Vectors
zooms
Posts: 4
I am using the propeller in a class project and I am trying to draw a vector based on a starting point, angle, and magnitude. I am going to use this to make a wheel spin using the tv and the graphics objects.
Comments
Good luck in your class project.
Baggers.
PS, don't forget to post pics of the finished project.
Perry
I used the vec function to create some clock type graphical elements see:
http://forums.parallax.com/showthread.php?p=682917
For a wheel you could make a vector sprite like a star for the spokes and use arc for the rim, then move the rim and move and rotate the spokes for the rotation effect as it rolls. Using PI in there somewhere will make it look more realistic.
Graham
So when defining a sprite you start at 0,0 if you do $8000 + 13bit angle then it will draw a line from 0,0 in that direction. If you did $4000 + 13bit angle then it will draw a point and the next vector will be drawn from there.
After the angle and type is defined the length of the vector.
The example from the demo of a triangle:
All angles are from the horizontal CCW. 0,0 in the sprite is the point that will be positioned at x,y as defined in the command vec.
If you draw your spokes comming out from 0,0 then any rotation will make them rotate around their centre.
Please do some experimentation and do actually read what is in graphics.spin to better understand it.
Graham
p.s. The pointer in my program is a vector sprite.
The angle is stored in 13 bits, this is %1111111111111 or $1FFF
zero represents both 0 degrees and 360 degrees so $1FFF represents just less than 360 and $2000 (which is $1FFF + 1) represents 360 degrees as well numerically but cannot be used because it is more than 13 bits however it can be divided up and used like in this case. The +1, and -1 used are to ensure that the total comes to 180 degrees, the total angle within a triangle accounting for the lack of fractional values I think.
Graham
I've been fooling around a bit, here's what I came up with for some spokes. I converted to 360 degrees to make it easier to read at a cost of resolution for angle.
-Martin
An alternate means to use one line draw at various angles from your loop:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting Software
Southern Illinois University Carbondale, Electronic Systems Technologies
Post Edited (Martin Hebel) : 10/26/2007 2:11:45 AM GMT
What I hinted to was a not very popular creative use of arc, such as:
Post Edited (deSilva) : 10/29/2007 5:17:48 PM GMT
Looks like I need to upgrade my graphics.spin it doesn't even have an arc command.
Graham
But - oops - did I delete the gr.clear as well? Sorry, the gr.clear should have stayed in it... darn on the fly editing of working code.
Graham
Indeed gr.arc(centerX , centerY , length, length, angle*$2000/360 , 0, 1, 3)
is not trivial...