Recent

Author Topic: Vector Drawing - where to start?  (Read 2655 times)

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #30 on: June 01, 2020, 10:51:59 pm »
This is the radius of the big blue circle.
Lazarus 2.0.6 Windows 10 64bits

J-G

  • Hero Member
  • *****
  • Posts: 550
Re: Vector Drawing - where to start?
« Reply #31 on: June 01, 2020, 10:58:40 pm »
 :-[  Ah  -  you noticed :) 

I've found the reason why I put 4176  which is 261º,    add 18º (pi / 2N) to that and you get 279    so when I was being idle and using a calculator ( I need it for a 16* multiplication :) ) I must have accidentally entered a 9 instead of a 0 as the last digit !!   So yes 4032 is what the 5th argument should be, However, the declaration for RadialPie is :

     procedure RadialPie(x1, y1, x2, y2, StartAngle16Deg, Angle16DegLength: Integer);

I read that as asking for the Length of the Arc rather than the End Point.

But thanks for the confirmation WP  -  my concern was that I might be mistaken in thinking that X1,Y1 could be negative.  I'll now (well, probably tomorrow) set about starting from scratch with a new project and see how far I can get.
FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 550
Re: Vector Drawing - where to start?
« Reply #32 on: June 01, 2020, 11:16:09 pm »
This is the radius of the big blue circle.
You are not wrong there marcio  BUT  -  it IS the 'Constant Diameter' of the Reuleaux Polygon  -  the Yellow shape behind the Red Sector. Which is what this project is all about.

If you haven't come across Reuleaux Polygons before you can be forgiven for thinking that any shape that is not a circle cannot possibly have a 'Diameter'. The piston in a Wankel Engine is a Reuleaux Triangle. The UK 50p & 20p coins are Reuleaux Heptagons - They are that shape for some element of security but also so that they can be used in vending machines.  If they didn't have a constant diameter they couldn't be checked mechanically.

FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 7250
Re: Vector Drawing - where to start?
« Reply #33 on: June 01, 2020, 11:38:14 pm »
However, the declaration for RadialPie is :

     procedure RadialPie(x1, y1, x2, y2, StartAngle16Deg, Angle16DegLength: Integer);

You are right, I only read the comment header of the source code where EndAngle16Deg is mentioned, but a few lines below it is Angle16DegLength:

Code: Pascal  [Select][+][-]
  1. {------------------------------------------------------------------------------
  2.   Method:   TCanvas.RadialPie
  3.   Params:   x1, y1, x2, y2, StartAngle16Deg, EndAngle16Deg: Integer
  4.   Returns:  Nothing
  5.  
  6.   Use RadialPie to draw a filled pie-shaped wedge on the canvas.
  7.   The angles StartAngle16Deg and EndAngle16Deg are 1/16th of a degree.
  8.   For example, a full circle equals 5760 (16*360).
  9.   Positive values of Angle and AngleLength mean
  10.   counter-clockwise while negative values mean clockwise direction.
  11.   Zero degrees is at the 3'o clock position.
  12.  
  13.  ------------------------------------------------------------------------------}
  14. procedure TCanvas.RadialPie(x1, y1, x2, y2,
  15.   StartAngle16Deg, Angle16DegLength: Integer);
  16. begin
  17.  ...
  18.  

Then I confirmed it with this test:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PaintBox1Paint(Sender: TObject);
  2. var
  3.   R: TRect;
  4. begin
  5.   Paintbox1.Canvas.Brush.Color := clWhite;
  6.   Paintbox1.Canvas.FillRect(0, 0, Width, Height);
  7.   R := Rect(50, 50, Paintbox1.Width - 50, Paintbox1.Height - 50);
  8.   Paintbox1.Canvas.Brush.Color := cLRed;
  9.   Paintbox1.Canvas.RadialPie(R.Left, R.Top, R.Right, R.Bottom, 90*16, 10*16);
  10. end;

I fixed the typos in trunk.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #34 on: June 02, 2020, 06:31:44 am »
Hi, see if it is useful.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   Spin;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.  
  18.     Im1: TImage;
  19.     Label1: TLabel;
  20.     SpEd1: TSpinEdit;
  21.     // I prefer to draw on an TImage because the drawing does
  22.     // not go out after changing the state or resizing the form.
  23.  
  24.     procedure Button1Click(Sender: TObject);
  25.     procedure SpEd1Change(Sender: TObject);
  26.   private
  27.     k: integer;
  28.  
  29.   public
  30.  
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1; { width=800 x height=800 and color white }
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. procedure TForm1.Button1Click(Sender: TObject);
  43. var
  44.   c1, c2, p1: TPoint;
  45.   r1, a2, i: integer;
  46.   r2: Real;
  47. procedure myDrawArc( da2: integer );
  48. begin
  49.   c2:= Point( round( c1.x - r1 * cos( da2 * pi / 180 )),
  50.     round( c1.y + r1 * sin( da2 * pi / 180 )));
  51.   Im1.Canvas.AngleArc( c2.x, c2.y, round( r2 ), da2 - 18, 36 );
  52. end;
  53. begin
  54.   with Im1.Canvas do
  55.   begin
  56.     Pen.Color:= clRed;
  57.     Pen.Style:= psSolid;
  58.     pen.Width:= 2; // If = 1 maybe make some leak floodfill.
  59.  
  60.     r1:= StrToInt( SpEd1.Text ); // Polygon radius
  61.  
  62.     k+= 5; // Delta rotate angle.
  63.     a2:= round( 270 + k );
  64.     c1:= Point( 400, 400 ); // Polygon center (center form)
  65.  
  66.     PenPos:= Point( c1.x + r1, c1.y );
  67.     Brush.Color:= clWhite;
  68.     FloodFill ( c1.x, c1.y, clRed, fsBorder );
  69.     Clear;
  70.  
  71.     //AngleArc( c1.x, c1.y, r1, 0,360 ); // Circumscribed circle.
  72.  
  73.     r2:= 2 * r1 * cos( pi / 10 );
  74.  
  75.     p1:= Point(
  76.       round( c1.x + r1 * cos(( a2 - 36 ) * pi / 180 )),
  77.       round( c1.y - r1 * sin(( a2 - 36 ) * pi / 180 )));
  78.  
  79.     PenPos:= p1; // Start point
  80.  
  81.     for i:= 1 to 5 do
  82.       myDrawArc( a2 + 72 * ( i - 1 ));
  83.  
  84.     LineTo( p1 ); // Guarantee to close polygon.
  85.  
  86.     PenPos:= Point( c1.x + r1, c1.y );
  87.     Brush.Color:= clRed;
  88.     FloodFill ( c1.x, c1.y, clRed, fsBorder );
  89.   end;
  90. end;
  91.  
  92. procedure TForm1.SpEd1Change(Sender: TObject);
  93. begin
  94.   Button1.Click;
  95. end;
  96.  
  97. end.  

I hope to be contributing.

Lazarus 2.0.6
Windows 10 64bits
« Last Edit: June 02, 2020, 06:37:39 am by marcio2003 »
Lazarus 2.0.6 Windows 10 64bits

J-G

  • Hero Member
  • *****
  • Posts: 550
Re: Vector Drawing - where to start?
« Reply #35 on: June 02, 2020, 11:47:28 am »
Thanks for your contribution Marcio  -  all input is potentially useful since a second/third/fourth pair of eyes (brain) on any problem will advance knowledge.

You have certainly addressed issues that - although I was aware of  -  hadn't really considered.

There are some basic parameters which you have not picked up on though.

First - there are only two variables that are known  -  the number of sides [N] and the 'Constant Diameter' [D]  -  therefore inputting the 'Radius' is not possible. 

Second - rotating the Polygon cannot be done around the centre of the image, it must be done so that the top and bottom both remain at the same point on the TImage   -  ie. It could be that the Polygon started life outside the TImage to the left and 'rolled' along a line drawn at (say) 50px from the bottom.

FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #36 on: June 02, 2020, 02:35:31 pm »
Hi,
This was just to start.
I know that what I did is not what the problem requires.
I needed to get into geometric issues and TCanvas commands.
I know how to solve it, I know the way forward and I will need time to reach it.
But now I go to my job and when I take a break I will try to find what you want.
Sorry for my bad English.
« Last Edit: June 02, 2020, 02:39:27 pm by marcio2003 »
Lazarus 2.0.6 Windows 10 64bits

J-G

  • Hero Member
  • *****
  • Posts: 550
Re: Vector Drawing - where to start?
« Reply #37 on: June 03, 2020, 09:12:54 pm »
'Bumped' to bring attention to the edit in reply #28  :-[
FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #38 on: June 03, 2020, 09:38:32 pm »
Hi, just a few conclusions:
1. The so-called "Constant Diameter" is wrong, because it does not fit the definition of diameter, better to call it "Constant Height (H)" or "Turning Radius (see considerations below)";
2. Reuleax Polygon (RP) when used to roll overlapping objects does not rotate around an axis contained within the RP;
3. It makes a set of rotations of (Pi / N) each having the vertices as axis, thus, the radius of each rotation will be the height defined in (1);
4. These rotations will alternate either with an upper vertex as an axis or with a lower vertex as an axis, starting when a vertex touches the surface;
5. To exemplify, we will use the polygon with an upper vertex (as you drew), the vertex will remain fixed on the upper surface until the rotation of (Pi / (2N) is completed), when this rotation is finished, a vertex will touch the lower surface , inverting the mechanism, now this vertex will remain fixed on the lower surface until the rotation of (Pi / N) is completed and when this rotation is finished a vertex will touch the upper surface, inverting the mechanism again and so on.
6. Note above that in this example only the first rotation is (Pi / (2N)), the others will be (Pi / N), because the initial position considers the base supported in the middle of the arc;
7. Successive rotations have their "Constant Diameter" as radius, so it is not a diameter but a Radius (1).
8. Each of the "alternating rotations" will provide a horizontal displacement of H*(Pi/N);
9. An algorithm to animate this movement does not seem complex now that I understand the mechanism, but it would take more time.
10. I didn't have time to review what I wrote, so consider the existence of some errors on my part, I would appreciate corrections.
Well, I hope I'm not wrong in my conclusions.
« Last Edit: June 03, 2020, 09:48:28 pm by marcio2003 »
Lazarus 2.0.6 Windows 10 64bits

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #39 on: June 03, 2020, 09:45:36 pm »
As you said that H (your Constant Diameter) and N are known, everything is simple now, because what i conclude is valid for any RP.
« Last Edit: June 03, 2020, 10:53:44 pm by marcio2003 »
Lazarus 2.0.6 Windows 10 64bits

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #40 on: June 03, 2020, 09:54:52 pm »
To better understand the scrolling mechanism of the RP it may be better to make a prototype.
Lazarus 2.0.6 Windows 10 64bits

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #41 on: June 03, 2020, 10:42:32 pm »
When RP has a vertex in contact with the upper surface, the lower surface will be in contact with an arc and the inversion will occur when the vertices coincide touching both surfaces.
Lazarus 2.0.6 Windows 10 64bits

J-G

  • Hero Member
  • *****
  • Posts: 550
Re: Vector Drawing - where to start?
« Reply #42 on: June 03, 2020, 10:43:57 pm »
Since you seem to have a keen interest Marcio, I'll point you to a video (the first I've made) showing how the Reuleaux polygons work as a 'Boggie'. It's less than two minutes long and some of that can be ignored but it's too large to add as an attachment.

         http://www.crescentcomputing.co.uk/Reuleaux/Reuleaux%20Boggie.mp4

will automatically start it.

You suggested making a 'prototype', well, that's exactly what I did last week  ;D   You'll see that I've made both a Triangle and a Pentagon.  -  I know exactly how they 'work', what I didn't know before I asked this question was how could I draw them in a Pascal program.

I must insist that 'D' IS the diameter - I know that the length of it must also be used in drawing calculations as a radius but the thing about the practical use of the shape in the real world (ie. as a coin), is that this 'Diameter' (being constant) is the most important attribute.

Your description of how the centre of rotation changes from top to bottom - initially after pi/2N and thereafter every pi/N is quite correct. (I knew that  ;) )  Though you may have missed the fact that the centre of rotation with a 'point' at the top moves horizontally whereas with a point at the bottom it is fixed.



« Last Edit: June 03, 2020, 11:01:09 pm by J-G »
FPC 3.0.0  Lazarus 1.6  Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 7250
Re: Vector Drawing - where to start?
« Reply #43 on: June 03, 2020, 11:16:43 pm »
I'll point you to a video (the first I've made) showing how the Reuleaux polygons work as a 'Boggie'.
Nice
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

marcio2003

  • New Member
  • *
  • Posts: 40
Re: Vector Drawing - where to start?
« Reply #44 on: June 03, 2020, 11:26:44 pm »
Great prototype.
Do you work in an educational institution?
Some observations:
1. I believe that the connection between the axles only served to maintain the distance between the RPs to provide tension on the belt.
2. Have you tried to remove the belt?
3. I believe that they are not necessary for synchronism because the arcs have the same radius (H or constant diameter).
4. If it works without the belt, I believe you can also remove the connection between the axles.
5. Without the timing obtained with the belt to prevent any vertex from sliding, it would be advisable to have a rubberized (or similar) surface on the running surfaces of the RP.
Tell me more about the app, maybe I can help you.
Lazarus 2.0.6 Windows 10 64bits

 

TinyPortal © 2005-2018