LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

draw a simple rectangle

I have written a simple VI program and would like to have a preview option. The preview would only be two parallel lines with both right and left sides adjustable based on the operator settings. Affectively I need to draw a rectangle with the right and left hand sides angle changeable.

I have spent hours trying to find a simple XY graph (seems like you could do this with an XY graph) but I can�t find a simple example. Half the examples I found where miles over my head and the other half didn�t run. I have not mastered arrays yet.

1- Does anyone know if you can draw a square with a XY graph?
2- Does anyone know of a really simple example (not using arrays) to draw a rectangle?
3- Is the XY graph the best way to draw a rectangle?

T
hank you for any suggestions you may have.
0 Kudos
Message 1 of 9
(8,476 Views)
1) Yes.
2) Rectangles, yes -- trapizoids, no.
3) Best? Based on what criteria? Speed? Ease of coding? Asthectics? Only you can decide "Best".

Simplified examples attached.

Good luck.
Download All
Message 2 of 9
(8,476 Views)
> 1- Does anyone know if you can draw a square with a XY graph?
> 2- Does anyone know of a really simple example (not using arrays) to
> draw a rectangle?
> 3- Is the XY graph the best way to draw a rectangle?
>

This will be quite simple, but it will require you to use arrays to some
extent along with some trig.

To draw an array that is not rotated at all, you need four points such
as (0,0) (0,1) (1,1) (1,0). If drawing the outline, you will want to
include the first point again as the fifth element in the array.

To rotate a point by theta about the origin, you will want to multiply
the X by the cosine of theta and the Y by the sine of theta. To rotate
a shape like the rectangle by theta about the origin, you multiply each
point in the same way.


It gets a bit more complicated if you wish to rotate them about another
point. You will want to offset all the points, do the rotation, then
add the offset back.

If this is too condensed, please look for a tutorial about graphics. It
is usually quite easy to find tutorials on various University sites.

Finally, if you wish to do more complex graphics, you might want to
consider using the picture control instead of the cartesian graph. The
graph is quite flexible, but it is a graph, and not a drawing tool.

Greg McKaskle
0 Kudos
Message 3 of 9
(8,476 Views)
This will be a good opertunity to learn about arrays.

Find the Robot example;

Find Examples>>>Building User Interfaces>>>Displaying Data>>>Pictures>>>Robot.vi

I use this to learn how to work with pictures.

The Picture functions include a VI called "Draw Rect.vi"

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(8,476 Views)
Just what I was looking for in your XY graph example. Than you so much!!! The �PictureSquare.vi� didn�t work for me as I can�t find �draw multiple lines.vi�. I am not sure what my company had bought other then Labview 6 in the way of add-ons. I believe some of the drawing stuff is extra?

I ended up using �Pict Ring� function and although it is very basic is works really well. Because both horizontal lines are always the same I simply drew (with Corel Draw) every angle from 15 to 165 degrees (my max angles). Then doing some basic control modifications I made the control completely transparent allowing the angles to over lap the horizontal lines. When the angle is set to 45 degrees my program sets the Pict Ring to 45 and accordingly the 45 degree angle i
s displayed (cool).

However when I have time I will look at using the XY Graph because I believe it is a more elegant solution.

Again thank you very much for your help!!
0 Kudos
Message 5 of 9
(8,476 Views)
Thank you for your suggestions. I do need to study up on arrays as I have many uses for them and I have yet to master them in any language. Good point on a graph being a graph and not a drawing tool. That is an area I was unclear on.

I ended up using �Pict Ring� function and although it is very basic it works really well. Because both horizontal lines are always the same I simply drew (with Corel Draw) every angle from 15 to 165 degrees (my max angles). Then doing some basic control modifications I made the control completely transparent allowing the angles to over lap the horizontal lines. When the angle is set to 45 degrees my program sets the Pict Ring to 45 and accordingly the 45 degree angle is displayed (cool).

Again thank you so much for you
r help!!!
0 Kudos
Message 6 of 9
(8,476 Views)
Good suggestion but for the life of me I can�t find the �Robot.vi�. I have Labview 6 but I wonder if I need some kind of drawing add-on? I think my company just purchased plain Labview 6 as I don�t seem to have the drawing functions I have read about or you are talking about.

I ended up using �Pict Ring� function and although it is very basic it works really well. Because both horizontal lines are always the same I simply drew (with Corel Draw) every angle from 15 to 165 degrees (my max angles). Then doing some basic control modifications I made the control completely transparent allowing the angles to over lap the horizontal lines. When the angle is set to 45 degrees my program sets the Pict Ring to 45 and accordingly the 45 degree angle is displayed
(cool).

Again thank you so much for your help!!!
0 Kudos
Message 7 of 9
(8,476 Views)
Technicaly speaking, the "Pict Ring" is faster than using the "Picture" functions anyway.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 9
(8,476 Views)
> Technicaly speaking, the "Pict Ring" is faster than using the
> "Picture" functions anyway.
>

The pict ring might be a bit faster, but both of these should be fast
enough to keep up with the human eye. The major difference between them
will likely be the size of the panel. A ring with lot of images can get
quite large.

If you have the base package of LV, I do not think that include the
picture control features. When you get ready to use the XY graph, the
trig methods described earlier should help.

Greg McKaskle
0 Kudos
Message 9 of 9
(8,476 Views)