Results 1 to 5 of 5

Thread: Transverse to longitudinal wave representation?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    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

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,063

    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
    Attached Files Attached Files
    Last edited by LaVolpe; Nov 15th, 2014 at 12:22 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,256

    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
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,256

    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.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,921

    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
    
    Private Sub Form_Load()
      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

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width