Help me with this sine wave trig

BlitzMax Forums/BlitzMax Beginners Area/Help me with this sine wave trig

This should be reasonably simple but then again, so am I ^_^

I need the white dot to curve up and meet the red dot where I clicked i.e. I need to adjust the frequency of the wave.

The most obvious way to do this is to scale the
frequency
parameter in the formula:
z = -Sin( frequency * x + horiz_displacement ) * amplitude + vertical_displacement

...by somehow basing the change on the distance clicked from the origin but nothing I've tried gets the correct result.

Strict
Graphics 800, 600, 0


Global mouse_x:Float
Global mouse_y:Float
Global distance:Float
Global angle:Float
Global list:TList = CreateList()


Repeat
	Cls
	mouse_x = MouseX()
	mouse_y = MouseY()
	distance = getDistance( 0, 300, mouse_x, mouse_y )
	angle = getAngle( 0, 300, mouse_x, mouse_y )
	
	If MouseDown(1)
		ListAddLast( list, tObject.Create() )
	EndIf
	
	For Local obj:tObject=EachIn list
		obj.update()
		obj.draw()
	Next
	
	SetColor( 255, 255, 255 )
	DrawText("Distance from origin to mouse: "+distance, 0, 0)
	
	Flip
Until KeyHit(KEY_ESCAPE)


Function getAngle( x1:Double, y1:Double, x2:Double, y2:Double )
	Return ATan2( y2 - y1, x2 - x1 )
End Function


Function getDistance:Float(x1:Float, y1:Float, x2:Float, y2:Float)
	Local x_diff:Float = x2 - x1
	Local y_diff:Float = y2 - y1
	Return Sqr( (x_diff*x_diff) + (y_diff*y_diff) )
End Function


'---------------------
'--- Moving object ---
'---------------------
Type tObject
	Field x:Float
	Field y:Float
	Field z:Float
	Field x_target:Float
	Field y_target:Float
	Field dist_target:Float
	Field rot:Float
	
	Function Create:tObject()
		Local this:tObject= New tObject
		this.x = 1
		this.y = 300
		this.z = this.y
		this.x_target = mouse_x
		this.y_target = mouse_y
		this.rot = angle
		Return this
	End Function
	
	
	Method update()
		If x > 800 Or x < 0 Or y < 0 Or y > 600
			ListRemove( list, Self )
			Return
		EndIf
		
		dist_target = getDistance( 0, 300, x_target, y_target )
		
		x:+2 * Cos( rot )
		y:+2 * Sin( rot )

		'-- Fake the white pixel travelling at an altitude which we refer to as z		
		Local frequency:Float             = 0.8
		Local horiz_displacement:Float    = 0
		Local amplitude:Float             = 200
		Local vertical_displacement:Float = y
		z = -Sin( frequency * x + horiz_displacement ) * amplitude + vertical_displacement
	End Method
	
	
	Method draw()
		'White is the "real" object
		SetColor( 255, 255, 255 )
		Plot(x, z)
		
		'Red is the "shadow" object, the object's footprint
		SetColor( 255, 0, 0 )
		Plot(x, y)
	End Method
End Type


to make the objects meet at the point where the mouse was clicked, you must force the sine function to be an integer number of half-waves along the vector your red object follows, from its beginning point to the point where the mouse was clicked.

here... in your update method change the frequency to this:
Local frequency:Float = n*180/dist_target

... where n is the integer number of half-wavelengths you want the white object to oscillate through until it intercepts the red object. I hope this is what you were after.

Wow, that's some crazy maths. Still I like a challenge!

After some hard thinking, the frequency you need is:

Local frequency:Float             = 180/x_target
Edit: Damn, Queller beat me to it!

You guys are gold, thanks!