How to make a pendulum move with a given, changing, velocity - vb.net

I am currently stuck trying to figure out how I will make my pendulum move with its changing velocity, due to gravity. I attempted to do this:
Do Until StopProgram = True
Do Until Count = v
Application.DoEvents()
If DirectionNegative = False Then
Me.Refresh()
Count += 1
Angle += 1
RadianAngle = Angle * PlaceHolder
If Angle >= 51 Then
Angle = 49
DirectionNegative = True
End If
ElseIf DirectionNegative = True Then
Me.Refresh()
Count += 1
Angle -= 1
RadianAngle = Angle * PlaceHolder
If Angle <= -51 Then
Angle = -49
DirectionNegative = False
End If
End If
Loop
Count = 0
Loop
This makes the pendulum move with the v (Final velocity (Using SUVAT)) but currently this is working by making it run for however long v is, I would like the pendulum to swing X amount per second, where X changes depending on v. I have been told I should try this with multithreading but after researching this I am confused on the whole thing and I do not know where to begin with any of this, bar what I have.

Related

spacing between two points in 3d cordinate system

i am a bit new to this but I'm trying to create a randomly generated 3d coordinate points with equal spacing, I've tried using for each loop but im confused on how to use in. the purpose is to generate sphere around that point but some sphere are overlapping each other. thanks in advance. the code below is to show how I'm generating the sphere
For i = 0 To noofsp - 1
x = Rnd(1) * maxDist
ws1.Cells(i + 5, 2) = x
y = Rnd(1) * maxDist
ws1.Cells(i + 5, 3) = y
z = Rnd(1) * maxDist
ws1.Cells(i + 5, 4) = z
centers.Add({x, y, z})
Next
You'll need to check the new point against all the other points to make sure that your new point is at a greater distance that the sum of the radii of your new sphere and each sphere you're checking against
You'll need to use pythagoras' theorem to check that the distances and I found the code below from this site. The code on the site is written in c#, but here is the vb.net version.
Public Function Distance3D(x1 As Double, y1 As Double, z1 As Double, x2 As Double, y2 As Double, z2 As Double) As Double
' __________________________________
'd = √ (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2
'
'Our end result
Dim result As Double
'Take x2-x1, then square it
Dim part1 As Double = Math.Pow((x2 - x1), 2)
'Take y2-y1, then square it
Dim part2 As Double = Math.Pow((y2 - y1), 2)
'Take z2-z1, then square it
Dim part3 As Double = Math.Pow((z2 - z1), 2)
'Add both of the parts together
Dim underRadical As Double = part1 + part2 + part3
'Get the square root of the parts
result = Math.Sqrt(underRadical)
'Return our result
Return result
End Function
To generate the spheres, you would need to expand your code to include checking the new point against all the previously generated points. That code is below with comments.
I have assumed the definition of a variable called minDistance to specify how far apart the centre of the spheres should be. I'm also assuming that all the spheres are the same size. The number should be twice the radius of the spheres
Private Sub GenerateSpheres()
Randomize
For i As Integer = 0 To noofsp - 1
Dim distanceOK As Boolean = False
Dim x, y, z As Integer
'keep generating points until one is found that is
'far enough away. When it is, add it to your data
While distanceOK = False
x = Rnd(1) * maxDist
y = Rnd(1) * maxDist
z = Rnd(1) * maxDist
'If no other points have been generated yet, don't bother
'checking your new point
If centers.Count = 0 Then
distanceOK = True
Else
'If other points exist, loop through the list and check distance
For j As Integer = 0 To centers.Count - 1
'if the point is too close to any other, stop checking,
'exit the For Loop and the While Loop will generate a new
'coordinate for checking, and so on
Dim dist As Integer = Distance3D(centers(j)(0), centers(j)(1), centers(j)(2), x, y, z)
If dist <= minDistance Then
distanceOK = False
'exit the For loop and start the next iteration of the While Loop
Continue While
End If
Next
'If all previous points have been checked none are too close
'flag distanceOK as true
distanceOK = True
End If
End While
'ws1.Cells(i + 5, 2) = x
'ws1.Cells(i + 5, 3) = y
'ws1.Cells(i + 5, 4) = z
centers.Add({x, y, z})
Next
End Sub

Dance Dance Revolution Game

http://i44.tinypic.com/znlvra.png
So I got this game like dance dance revo it wors Ok it says good and perfect when you hit an arrow i got a problem with the perfect hit it works depends on the speed on the arrows but I got an option easy, medium and hard basically easy is the slowest and hard is the fastest in the medium speed it I never ever hit a perfect so I'm asking if you guys have a better method to get the perfect or help me improve this code:
'Perfect Hit
If (RArrowDown.Top = ArrowDown.Top) And RArrowDown.Visible = True Then
TimerMain.Enabled = False
Hit += 1
Score += 20
RArrowDown.Visible = False
Perfect.Visible = True
TimerPerfect.Enabled = True
Combo_Counter += 1
RandomTime_1.Enabled = True
'End If
'Good Hit
ElseIf (RArrowDown.Top <= ArrowDown.Top + ArrowDown.Height) And (ArrowDown.Top <= RArrowDown.Top + RArrowDown.Height) And RArrowDown.Visible = True Then
TimerMain.Enabled = False
Hit += 1
Score += 10
RArrowDown.Visible = False
Good.Visible = True
TimerGood.Enabled = True
Combo_Counter += 1
RandomTime_1.Enabled = True
End If
I think a better way is to get a value indicating how far off from perfect the keypress is (I think it is very unliekly that someone actually gets it perfectly), then act on this value. You can then tweak the bands that give you a perfect or good hit:
Dim offset as Integer
If [Right Arrow Pressed]
offset = RarrowDown.Top - ArrowDown.Top
End If
Select Case offset
case is 0 to 3
'perfect
case 4 to 10
'good
case 11 to 20
'poor
case else
'missed
End Select

Which points are co-linear & in sequence (i.e. which two points I am between)

I have longitude and latitude of my position, and I have a list of positions that is ordered as a list of points(long/lat)) along a road. How do I find out which two points I am between?
If I just search for the two nearest points I will end up with P2 and P3 in my case in the picture.
I want to know how to find out that I'm between point p1 and p2.
The list of points I will search will be database rows containing latitude and longitude so pointers to how to build the sql-query, linq-query or pseudo code, everything that points me to the best solution is welcome. I'm new to geolocation and the math around it so treat me as an newbie. ;)
(The list of points will be ordered so P1 will have an id of 1, p2 will have an id of 2 and so on. )
Bear in mind that what you propose might become really complex (many points under equivalent conditions) and thus delivering an accurate algorithm would require (much) more work. Taking care of simpler situations (like the one in your picture) is not so difficult; you have to include the following:
Convert latitude/longitude values into cartesian coordinates (for ease of calculations; although you might even skip this step). In this link you can get some inspiration on this front; it is in C#, but the ideas are clear anyway.
Iterate through all the available points "by couples" and check whether the point to be analysed (Mypos), falls in the line formed by them, in an intermediate position. As shown in the code below, this calculation is pretty simple and thus you don't need to do any pre-filtering (looking for closer points before).
.
Dim point1() As Double = New Double() {0, 0} 'x,y
Dim point2() As Double = New Double() {0, 3}
Dim pointToCheck() As Double = New Double() {0.05, 2}
Dim similarityRatio As Double = 0.9
Dim minValSimilarDistance As Double = 0.001
Dim similarityDistance As Double = 0.5
Dim eq1 As Double = (point2(0) - point1(0)) * (pointToCheck(1) - point1(1))
Dim eq2 As Double = (point2(1) - point1(1)) * (pointToCheck(0) - point1(0))
Dim maxVal As Double = eq1
If (eq2 > eq1) Then maxVal = eq2
Dim inLine = False
Dim isInBetween As Boolean = False
If (eq1 = eq2 OrElse (maxVal > 0 AndAlso Math.Abs(eq1 - eq2) / maxVal <= (1 - similarityRatio))) Then
inLine = True
ElseIf (eq1 <= minValSimilarDistance AndAlso eq2 <= similarityDistance) Then
inLine = True
ElseIf (eq2 <= minValSimilarDistance AndAlso eq1 <= similarityDistance) Then
inLine = True
End If
If (inLine) Then
'pointToCheck part of the line formed by point1 and point2, but not necessarily between them
Dim insideX As Boolean = False
If (pointToCheck(0) >= point1(0) AndAlso pointToCheck(0) <= point2(0)) Then
insideX = True
Else If (pointToCheck(0) >= point2(0) AndAlso pointToCheck(0) <= point1(0)) Then
insideX = True
End If
if(insideX) Then
If (pointToCheck(1) >= point1(1) AndAlso pointToCheck(1) <= point2(1)) Then
isInBetween = True
ElseIf (pointToCheck(1) >= point2(1) AndAlso pointToCheck(1) <= point1(1)) Then
isInBetween = True
End If
End If
End If
If (isInBetween) Then
'pointToCheck is between point1 and point2
End If
As you can see, I have included various ratios allowing you to tweak the exact conditions (the points will, most likely, not be falling exactly in the line). similarityRatio accounts for "equations" being more or less similar (that is, X and Y values not exactly fitting within the line but close enough). similarityRatio cannot deal properly with cases involving zeroes (e.g., same X or Y), this is what minValSimilarDistance and similarityDistance are for. You can tune these values or just re-define the ratios (with respect to X/Y variations between points, instead of with respect to the "equations").
An equivalent solution in Scala for clarity:
def colinearAndInOrder(a: Point, b: Point, c: Point) = {
lazy val colinear: Boolean =
math.abs((a.lng - b.lng) * (a.lat - c.lat) -
(a.lng - c.lng) * (a.lat - b.lat)) <= 1e-9
lazy val bounded: Boolean =
((a.lat < b.lat && b.lat < c.lat) || (a.lat > b.lat && b.lat > c.lat)) &&
((a.lng < b.lng && b.lng < c.lng) || (a.lng > b.lng && b.lng > c.lng))
close(a,b) || close(b,c) || (colinear && bounded)
}
def close(a: Point, b: Point): Boolean = {
math.abs(a.lat - b.lng) <= 1e-4 && math.abs(a.lat - b.lng) <= 1e-4
}

number variable won't addition by 1 and display in a label everytime the timer counts 1000ms. - vb.net

Here is my code:
number = 1
If chkFN.Enabled = True Then
If ProgressBar1.Value < 100 Then
number += 1
lblFN2.Text = number
Else
lblFN2.Text = "0"
End If
End If
i have a checkbox, progressbar and a label.
when the progress bar is lower than 100 i want the number variable to + 1 every time the timer counts 1. I've tried "X = X + 1" - it worked to a point but i need to reset the variable to "0" when the progressbar hits 100% and when i click the stop button.
while I've been typing this i've also tried:
X = X + 1
If chkFN.Enabled = True Then
If ProgressBar1.Value < 100 Then
lblFN2.Text = X + 1
ElseIf AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded
Then
X = 0
lblFN2.Text = "0"
Else
X = 0
lblFN2.Text = "0"
End If
End If
But when you start the timer again it just resumes from it's last number e.g. "13" and doesn't reset to "0".
Thanks for the help guys :)
Use your first code, but add in
number += 1
to the Else condition. You need to reset the variable or it just increments it again.

How to Detect if Sprite is going Up or Down

I Use the following code to detect if a sprite should be going up or down and the response
If (pos.Y + 100) >= Sprite.BottomY Then
Going_up = True
pos.Y = Sprite.BottomY - 130
End If
If pos.Y <= Sprite.TopY Then
Going_up = False
pos.Y = Sprite.TopY - 1
Vel.Y = 3
End If
then
If Going_up Then
Vel.Y -= CSng(gameTime.ElapsedGameTime.TotalMilliseconds / 40)
pos.Y -= Vel.Y
Else
Vel.Y += CSng(gameTime.ElapsedGameTime.TotalMilliseconds / 40)
pos.Y += Vel.Y
End If
Sprite.velocity = Vel
Sprite.position = pos
but it's pretty terrible. It only works when the sprite starts at the top, and when I want to change the BottomY and TopY, it just starts glitching. What is a better to detect if the sprite should be going up or down?
Can you not just do:
If (Vel.Y > 0) Then
Going_up = True
' Do rest of up code
Else If (Vel.Y < 0) Then
Going_up = False
' Do rest of not going up code
End If
Something that might help is utilizing a getter and setter like this:
Essentially, you could create a tempX and tempY. Every 100ms compare the sprite's current properties with the temp variables.
Dim tempX As Double
Dim tempY As Double
While True
tempY = sprite.GetY()
If gameTime.ElapsedGameTime.TotalMilliseconds Mod 100 = 0 Then 'or something to sample the game time
If sprite.Vel.Y > tempY Then
Going_up = True
Else
Going_up = False
End If
End IF
End While
So you're sort of taking a sample of your game board to create approximate reference points that you can compare the actual value to. Hope that helps!
-sf