View Single Post
Old 02-06-2017, 03:07 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026

Originally Posted by abeginner View Post
... I need to draw a Perfect Square Shape so that I can then form an Equilateral Triangle using it, but the shape control seems to default to a rectangle instead of a perfect square. ...
What do you base that on?
An equilateral triangle where the base is one side of a square, the corner opposite of the base will not touch the edge of the opposite side of the square.
The height of an equilateral triangle is equal to Sin(60) * the base.
Think about it.
Start with three lines that are three sides of a square so are equal length.
Now tilt the left and right sides toward the center, each rotating 60 degrees to meet in the center. The tops of those lines will meet about 86.6 percent of the way up from the center of the base.

Also, in your code you're not even using the corners of the square shape you created, but are using the X,Y mouse position that the user dragged to, so your equilateral triangle isn't using the square in any case.

p.s. I played around further with the code, and I think I see where you're coming from. One thing to note is you have the scalemode set to User so there is the chance the pixels are not square units, but the main issue is that setting "OutlineRectangle.Shape = 1" to make the shape a square doesn't make the rectangle square, it just draws the largest square that will fit, centered within the bounds of the rectangle defined.
It is the same idea if you selected a circle shape. It doesn't make the rectangle defining the bounds of the shape into a circle, it just draws the largest circle that will fit, centered, within those bounds.

So, you probably want to do the same thing, essentially, except you may want the top of the triangle to always touch the top of the rectangle, rather than be centered within the bounds of the rectangle.
An example would be to determine the shortest side of the rectangle and use that for your base. Your centerX calculation would stay the same, and the top Y.
You would use the shortest side as the length of your triangle sides, so set the left and right offsets from center to 1/2 that length.
Your bottom Y value would be the Top + .866 * that length.
   If OptionEquil.Value = True Then
   'OutlineRectangle.Shape = 1 ' A square  'doesn't help, so not needed
     If initialX <> 0 And initialY <> 0 Then
       Dim legLength As Single
       Dim leftSide As Single, rightSide As Single, centerX As Single, BottomY As Single

       With OutlineRectangle
         'Choose the shortest side of the rectangle for the triangle side length
         If .Width < .Height Then   
           legLength = .Width       
           legLength = .Height
         End If
         centerX = .Left + .Width / 2
         leftSide = centerX - legLength / 2
         rightSide = centerX + legLength / 2
         BottomY = .Top + legLength * 0.866
         Picture1DrawCanvas.Line (centerX, .Top)-(rightSide, BottomY) 'centerTop to bottom right
         Picture1DrawCanvas.Line -(leftSide, BottomY)                 'continue to bottom left
         Picture1DrawCanvas.Line -(centerX, .Top)                     'continue back to centerTop
       End With
     End If
   End If
Originally Posted by abeginner View Post
Also what sort of picture box can be used to improve the picture quality (antialias lines)?
I don't know of a user control that has been built that has antialising built in, but there may be some out there that will probably cost you money.
You could use GDI+, but that is some additional work, and someone like mms would probably be the most familiar with it. I have no experience with it and VB6. I don't know if there is a GDI available API call that will do it (didn't look, so there may be).
Originally Posted by abeginner View Post
Lastly, once each picture is drawn what can be done to move it to a slightly different position
If you're going to want to move or modify the shapes you're drawing, then you will have to save the information used to draw the shapes.
Right now you just draw the shape on an AutoRedraw buffer and have no memory of how you drew it after it is drawn. Since you have no way to redraw the shape, you have no way to make any modifications to it.

You will need to create a type, or a class to hold information about a shape, and then an array or collection of some sort to maintain those objects.
Then there is the matter of determining which shape you want to modify, and how to designate what modifications you want to do. Can be even more challenging if you allow shapes to overlap.
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 02-07-2017 at 12:08 PM.
Reply With Quote