LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulation

How do I draw rotating matrix of lines, like in the picture, in real time?

0 Kudos
Message 1 of 15
(1,352 Views)

First, show us what you've already tried....

 

In general:

  1. set up a WHILE loop with a FOR loop inside it
  2. set up an array of (line) start points and an array of end points, probably as a result of a calculation that runs once per iteration of the WHILE loop
  3. Feed the arrays of start and end points into the FOR loop using auto indexing
  4. use picture functions to move the pen to the start point and draw a line to the end point
  5. feed the resulting picture back to the next iteration of the FOR loop using a shift registe

 

0 Kudos
Message 2 of 15
(1,348 Views)

To be honest I'm new at Labview programming, so I couldn't make anything. Thank you for your advice. I attach my programm below. It's main goal is to simulate the Freedericks transition and the drawing is only a part of it.

Download All
0 Kudos
Message 3 of 15
(1,310 Views)

You have fallen into a common "trap" regarding LabVIEW -- because it is graphical, and "anyone can draw pictures and make lines", many new users assume that they can just "start using it" without understanding the underlying ideas behind LabVIEW, and without knowing the importance of good Style in creating LabVIEW code that (a) is designed to accomplish the given task, (b) is easy to understand and grasp, and (c) actually works.

 

A good thing to do is to learn LabVIEW.  At a bare minimum, spend half a day with the tutorials and other materials listed on the first page of this Forum.  If there are exercises, do them all.  Schor's Law -- you can't learn programming by reading a book, but you can learn it by writing Programs and getting them critiqued (and learning from your mistakes).

 

There are many ways to accomplish the task of "rotating a line" (whatever that means!).  Here's one way:

  • Forget LabVIEW for a moment.  What determines a line?  [Think high school geometry, where I learned "Two points determine a line".]
  • I understand you want "pictures" of a line.  What, in LabVIEW, can produce a "picture" of a line?  [You should be able to name at least three things that can do this -- consult the Front Panel Palette if you need hints].
  • What does it mean to "rotate a line"?  What (relatively simple) math do you have to do?
  • Most (other) Programming Languages don't embed the concept of "time" in the Language -- the goal is to execute the code "as fast as possible".  LabVIEW is different, as it is trying to emulate actual hardware.  Where does "time" enter into your thinking about this problem?
  • Without using LabVIEW, can you write a cogent description of the steps you would need to take to accomplish your goal?  Do not use terms such as "While Loop" or "Wires" -- use English (or your native language).
  • Once you have a complete grasp of the problem, think about how to implement it in LabVIEW.  Know the Problem First.

Bob Schor

 

P.S. -- it is a good thing that this is only a small part of a bigger problem.  Another Good Idea is to divide a Big Problem into smaller steps, and to tackle the smaller steps in isolation, and often first.  The ideas outlined above, however, will also apply to the Main Task, with the added suggestion that breaking it up into sub-Tasks (and, ultimately, into sub-VIs) will greatly improve the likelihood that you will be able to (a) accomplish the coding (as you will be doing many simple things instead of one huge complex thing), (b) understand and be able to explain your code to someone else (a great help in finding bugs and errors), and (c) have your code work correctly.

Message 4 of 15
(1,293 Views)

Thank you very much for your help. I actually watched a tutorial which led to my solution. By rotating a line I meant changing its direction by a given angle. I attach my solution below which requires a matrix of angles and later on draws those "molecules" with a given orientation on a 2D plane. The only thing I can't change is to resize the 2D picture indicator to fit it to the size of the "matrix of molecules"

0 Kudos
Message 5 of 15
(1,277 Views)

Great, you got something to work!  Almost, if I understand your last Post.

 

I decided to "play" with this a little.  I defined a Point as a Cluster of X, Y, and defined a Line as an Array of Points.  In this example, the line has only 2 points.  I wrote 5 very simple sub-VIs that did only one thing --

  • Shift, translates a line by adding a Point offset to each end.
  • Centroid, returns the middle of a 2-point Line.
  • Rotate about Origin, rotates a line about the Origin.
  • Rotate about Centroid, rotates a line about its Centroid.
  • Line to Graph, converts a Line to a format (Cluster of X Array, Y Array) suitable for plotting on a LabVIEW Graph.

Here's a Demo that takes a line from 0, 0 to 4, 5 and plots it rotated by 8 multiples of pi/10.  Here I plotted all of the lines so you could see it "statically" -- I can also plot it "dynamically" by moving the Graph indicator inside the For Loop, and see the line rotate.

DEMO Spin Line.pngSpin Line FP.png

The original line is in White.

 

A key to getting this to work with relatively little effort was breaking it up into such simple steps that "(almost) nothing can go wrong ...".  Here, for example is Rotate about Centroid -- I'll leave the rest as an Exercise for the Reader.

Rotate about Centroid.png

One final note:  instead of using Matrices, I used Complex arithmetic.

 

Bob Schor

 

P.S. -- now I'm starting to think about 3-D rotations (viewing a projection onto, say, the X-Y Plane) with rotation about the centroid of a "cloud of points" (a line is a "cloud" of two points, and the Specification of the Problem called for plotting lines, not points) about an arbitrarily-oriented axis (specified, say, by Azimuth and Elevation).  It would be a little more complicated than this example, but not by an order of magnitude (provided you take is slow ...).

0 Kudos
Message 6 of 15
(1,256 Views)

@Silly_student wrote:

How do I draw rotating matrix of lines, like in the picture, in real time?


Is this a static picture or an animation? ("Rotating" implies animation). To animate, you just need to redraw with new values at regular intervals. 

 

Many years ago, I posted this example drawing arrows with variable length and color. It can easily be simplified dramatically for lines of single color and lenght. 😄

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 7 of 15
(1,253 Views)

@Silly_student wrote:

By rotating a line I meant changing its direction by a given angle. 


If you use complex datatype, you don't need any trigonometry (sin, cos, etc.). Here's a very quick rewrite of my mentioned old example that can hopefully give you some ideas. This really does not need much code at all.

 

spinners.png

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 8 of 15
(1,243 Views)

@Silly_student wrote:

To be honest I'm new at Labview programming, so I couldn't make anything. 


Some comments on your original code:

  • There is (almost) never any need for EXT. Use DBL. Converting an integer to EXT does not magically give you more precision 😄
  • Writing from a terminal to a local variable of that terminal is just plain silly. None of your local variables are needed, just wire from the terminal.
  • There is a tool to initialize a matrix of a given size and dimension (and convert to a matrix if desired). You pyramid of FOR loops on the left is ridiculous. (See also)
  • Don't use matrix datatypes. A plain 2D array is sufficient. You don't do any linear algebra. (actually, all your formulas might possibly be replaced by matrix operations, hard to tell...).
  • Your while loop spins as fast as the computer allows. Probably not a reasonable choice.
  • Express VIs just obscure code. All can be done in plain g.

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 9 of 15
(1,242 Views)

And here's how the code could look like when operating on a 2D array of angles.

 

Spinners2.png


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 10 of 15
(1,231 Views)