|
-
Nov 6th, 2001, 09:01 PM
#1
Thread Starter
Hyperactive Member
Rotation 360 degrees
Could anyone help me out with this, I can't seem to put the math together for it. Let's say you have a line object on a VB form. It has the properties X1, X2, Y1, Y2 for it's two points coordinates. Based on a timer how could you get the two points to rotate in a perfect circle by incrementing and decrementing the coordinate values? I really need to see it in code, because I haven't been able to apply anything involving geometry yet. Thanks.
-
Nov 6th, 2001, 09:54 PM
#2
transcendental analytic
I recommend you learn the geometry part first.
the cartesian coordinate (x,y) for a polar coordinate (a,r)
(a=angle and r=radius) is
r*cos(a),r*sin(a)
the angles used with the vb trigonometry functions are in radians, 2pi making a full revolution, pi/180 a degree.
write angle a as a function of the time a(t)=k*t and you can increment it as a=a+k;
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 7th, 2001, 08:30 AM
#3
Thread Starter
Hyperactive Member
Could you explain that a little better?
All the timer needs to do is increment or decrement by a factor which will be a variable that will be recalculated.
I want the points to move around the circumference of the cirlce. Maybe like a pixel or two around the circumference every timer_event.
What kind of things do I need to determine? Do I need the diameter, how do I get the angle you're referring to?
-
Nov 7th, 2001, 09:13 AM
#4
transcendental analytic
You need to think systematically...
Your situation is this:
You have a function of time, the spinning line is your function output and time is it's input. depending on what time it is, your line will be at a different state.
The two endpoints of the line needs to be determined, and from the center of the line (or circle as you see it) you draw the line trough it from one endpoint to the other. The angle at which the line is passing trough the center is a function of the time: a(t)=k*t
The radius is as you define it constant, it's up to you how big circle you want.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 7th, 2001, 12:37 PM
#5
Thread Starter
Hyperactive Member
What is K? in k * t.
And this doesn't neccessarily have to be on a timer.
-
Nov 7th, 2001, 12:56 PM
#6
transcendental analytic
k is angular speed for the spin, what else would you like to apply this with?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 7th, 2001, 05:17 PM
#7
Trig and stuff
Hi ,see the atttached file , it's a early version of a 2D game
engine I wrote and has all those tricky maths stuff as functions
you will need your own grahics of course!
HTH
-
Nov 8th, 2001, 08:47 AM
#8
Thread Starter
Hyperactive Member
I appreciate the example, but it would take a week or two to review your code and understand every inch of it enough to even begin to figure out the geometry used.
How about when I get home I post the form I'm using and someone add the code to it. I'm sure it's not really extensive, it's just a matter of knowing the right math. (Which I don't know, I have gaps in my geometry knowledge.)
Thanks.
-
Nov 8th, 2001, 11:39 AM
#9
Addicted Member
Coming Up, some the exact code needed (once i figure out where i left that draw circle with lines code i did 2 years ago)
ok (5min later)
asummings Line1 is your line Object.
Code:
Sub UpdateLineRotation(line1 as line, Speed as Double)
dim CenterX as integer
dim CenterY as Integer
if line.x2 > line.x1 then
CenterX = (line1.x2 - line1.x1) /2
else
CenterX = (line1.x1 - line1.x2) /2
end if
if line.y2 > line.y1 then
CenterY = (line1.y2 - line1.y1) /2
else
CenterY = (line1.y1 - line1.y2) /2
end if
CurrentAngle = 'some one fill in the trig here, i can't remember how to do it off hand
if currentAngle < 180 then
CurrentReverseAngle = 180 + CurrentAngle
else
CurrentReverseAngle = 180 - CurrentAngle
end if
Radius = line1.length /2
ftemp = currentAngle + speed '(in degree's)
line1.x1 = CentreX + (Radius * Cos(fTemp * (3.1415926 / 180)))
line2.y1 CentreY + (Radius * Sin(fTemp * (3.1415926 / 180)))
ftemp = currentReverseAngle + speed '(in degree's)
line1.x2 = CentreX + (Radius * Cos(fTemp * (3.1415926 / 180)))
line2.y2 CentreY + (Radius * Sin(fTemp * (3.1415926 / 180)))
Doupt if that will work, but should give you an idea
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
-
Nov 8th, 2001, 12:35 PM
#10
Thread Starter
Hyperactive Member
I hope some one does fill in the trig there, but anyway you've been extremely helpful. That is what I'm looking for. Let me know when you figure out that CurrentAngle algorithm, because I forgot my Trig like 3 years ago.
-
Nov 8th, 2001, 03:06 PM
#11
is this what you mean?
Dim x1 As Long
Dim y1 As Long
Dim x2 As Long
Dim y2 As Long
Private Sub Form_Load()
x1 = Line1.x1
y1 = Line1.y1
x2 = Line1.x2
y2 = Line1.y2
Me.Show
End Sub
Private Function Track(ByRef X As Long, ByRef Y As Long, Angle As Integer, Optional Speed As Long, Optional Oppersite As Boolean)
'defaults
If Speed = 0 Then Speed = 1
'Track a point along a tragectory line
If Oppersite Then
X = (X - Sin(Angle / 57.2958) * Speed)
Y = (Y - -Cos(Angle / 57.2958) * Speed)
Else
X = (X + Sin(Angle / 57.2958) * Speed)
Y = (Y + -Cos(Angle / 57.2958) * Speed)
End If
End Function
Private Sub Timer1_Timer()
Track x1, y1, (Timer * 100) Mod 360, 100
Track x2, y2, (Timer * 100) Mod 360, 100
Line1.x1 = x1
Line1.y1 = y1
Line1.x2 = x2
Line1.y2 = y2
Line1.Refresh
End Sub
set timer1 interval to 1
x1 to 1800
x2 to 2000
y1 to 2500
y2 to 2500
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|