# Thread: Transverse to longitudinal wave representation?

1. ## Transverse to longitudinal wave representation?

Hi folks,
I'm trying to write a code to produce a sound tone where we can select the desired frequency.
In one picturebox I want to show the sine wave of that tone.

In the second picturebox I want to do the same, but instead of using a sine wave I want to show it using longitudinal waves.

How can I do that (representing that transverse wave into longitudinal one)?

For a graphic example, here you've a link where you can see what I'm talking about:
http://www.animatedscience.co.uk/blo...s/tl-wave.html  Reply With Quote

2. ## Re: Transverse to longitudinal wave representation?

Knowing 3-4 points, you can draw those using bezier curves, either using GDI or GDI+. The GDI API is named: PolyBezier. You should be able to find examples by googling it. The GDI+ function which can do nice blended curves is: GdipDrawBeziers

Edited:
Drawing the path/curve is one thing. Traversing it is another, if you & I are using 'traverse' the same way. Here's an old project (i.e., lost interest) that I wrote using GDI+ that creates curves/lines via GDI+ path APIs and then traverses the path, point by point & was an exercise of curiosity more than anything else. If you download this, simply run it then just click the "Path Tracing/Tracking Test" button.

Note: even if this is what you are looking for, you'll have to borrow the code & tweak it quite a bit for your purposes.

While playing, don't assume that the curves in the test routine have a gazillion points so they can be traversed. A bezier curve has 4 points, regardless how arced/flat or big/small the curve is. The code does calculate #n points per curve when the curve is actively being traversed. These points are created on demand & are customizable to allow greater/less accuracy. The number of points per curve segment are defined as: 1/accuracy where accuracy ranges between .001 ~ .5. Additionally, these points are in reference from curve start to curve end; just a segment of the entire path. The actual X,Y coordinate on the curve must be relative to the path start/end. Therefore the curve point used is closest curve point relative to the entire path based on time traveled. The NavigatePath function of the clsWAPath class is where the traverse point is calculated. You'll want to read up on "time to distance" relative to curves  Reply With Quote

3. ## Re: Transverse to longitudinal wave representation?

Jose_VB,

I'm not sure I've ever seen a longitudinal wave graphed as a true longitudinal wave. Traditionally, they are graphed as a transverse wave.

A longitudinal wave has only one dimension, which would just be a line when graphed. I suppose you could turn the line different colors to represent the changes in frequency, but that wouldn't be nearly as visually satisfying as just representing it as a transverse wave with a certain amplitude.

Elroy  Reply With Quote

4. ## Re: Transverse to longitudinal wave representation?

And yes, something like sound is certainly a longitudinal wave (typically thought of as many many sine waves combined to represent the timbre of the sound). But again, when graphed, they're usually shown "as if" they are transverse waves.  Reply With Quote

5. ## Re: Transverse to longitudinal wave representation?

Below is an example which produces the same animated output as the Flash-based Demo on the linked site:

Into a Form: (the vbRichClient5 library is used for the Spline-Drawing and the Bell-shaped gradients on the longitudinal lines)

Code:
```Option Explicit

Private Type Pt
x As Double
y As Double
End Type

Private SrfTrsv As cCairoSurface, SrfLngt As cCairoSurface
Private WithEvents T As cTimer, Points() As Pt

Private Const PxlW& = 700, PxlH& = 150, PtDist& = 9, Freq& = 5

Set SrfTrsv = Cairo.CreateSurface(PxlW, PxlH)
Set SrfLngt = Cairo.CreateSurface(PxlW, PxlH)
ReDim Points(0 To SrfTrsv.Width \ PtDist)

Set T = New_c.Timer(25, True)
End Sub

Private Sub T_Timer()
Dim i As Long
Static xShift As Double
For i = 0 To UBound(Points)
Points(i).x = i * PtDist
Points(i).y = 0.3 * PxlH * Sin((Points(i).x - xShift) / PxlW * 2 * Cairo.PI * Freq)
Next i
xShift = xShift + 2

DrawTrsv SrfTrsv.CreateContext
DrawLngt SrfLngt.CreateContext
End Sub

Private Sub DrawTrsv(CC As cCairoContext)
Dim i As Long
CC.SetSourceColor vbWhite: CC.Paint 'ensure white background
CC.TranslateDrawings 0, CC.Surface.Height / 2 'shift to the mid of the y-range
'draw the PolyLine for the Sinus
CC.SetLineWidth 1
CC.SetSourceColor vbRed
CC.PolygonPtr VarPtr(Points(0)), UBound(Points) + 1, False, splNone, True, True
CC.Stroke

'draw the Points of the Array, which make up the 'points of support' of the above Spline
CC.SetSourceColor vbBlue
For i = 0 To UBound(Points)
CC.ARC Points(i).x, Points(i).y, 3
CC.Fill
Next i
CC.Surface.DrawToDC hDC, 0, 0.15 * CC.Surface.Height
End Sub

Private Sub DrawLngt(CC As cCairoContext)
Dim i As Long, x As Double, Pat As cCairoPattern, Srf As cCairoSurface
CC.SetSourceColor vbWhite: CC.Paint 'ensure white background

'a Pattern which is blue at the center, but white-ish (near transparent) at the edges
Set Srf = Cairo.CreateSurface(14, CC.Surface.Height)
Set Pat = Cairo.CreateLinearPattern(0, 0, Srf.Width, 0)
Pat.AddGaussianStops_ThreeColors vbWhite, vbBlue, vbWhite, 0.1, 1, 0.1
Srf.CreateContext.Paint , Pat

'draw the Longitudinal-wave by applying the above pattern on each Points.x-pos
For i = 0 To UBound(Points)
x = Points(i).x + Points(i).y * 0.1 'add the sinuid y-value as the distance to x
CC.RenderSurfaceContent Srf, x - Srf.Width / 2, 0
Next i

CC.Surface.DrawToDC hDC, 0, 1.3 * CC.Surface.Height
End Sub

Private Sub Form_Terminate()
New_c.CleanupRichClientDll
End Sub```
The above code produces this output here: Olaf  Reply With Quote

sound #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•