Recent

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

marcio2003

  • Jr. Member
  • **
  • Posts: 69
Re: Vector Drawing - where to start?
« Reply #45 on: June 03, 2020, 11:37:53 pm »
... 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.
Not exactly, both vertex (upper and lower) are fixed on the respective contact surfaces, the difference is that the upper contact surface moves, consequently displacing the point that remains relatively fixed on it. But never simultaneously.
« Last Edit: June 03, 2020, 11:44:11 pm by marcio2003 »
Lazarus 2.0.10 Windows 10 64bits

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Vector Drawing - where to start?
« Reply #46 on: June 03, 2020, 11:52:27 pm »
I'll point you to a video (the first I've made) showing how the Reuleaux polygons work as a 'Boggie'.
Nice
Thanks WP  -  though I have to assume the Boggie rather than the Video  :D
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Vector Drawing - where to start?
« Reply #47 on: June 04, 2020, 12:18:21 am »
Great prototype.
Do you work in an educational institution?
No - and never have ---  I'm semi-retired but still build a few high spec PCs as and when called upon.  I also work in exotic woods to make Pens, Pepper mills, boxes etc. and the occasional jewellery project.

Quote from: marcio2003
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.
Yes it would work without belts and without the between axle links. I put both in - and used toothed belts - to keep the whole structure compact, and because I wasn't sure in my own mind that the Triangle and Pentagon would be 'happy' together.  If I were to make 3D versions they could roll in any direction but that is currently outside of my manufacturing capability.

Quote from: marcio2003
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.
Certainly, a high viscosity surface would be preferable but the fact is that there is no 'App' - it's just a bit of fun to keep my brain from atrophying  8-)
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Vector Drawing - where to start?
« Reply #48 on: June 04, 2020, 12:23:58 am »
... 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.
Not exactly, both vertex (upper and lower) are fixed on the respective contact surfaces, the difference is that the upper contact surface moves, consequently displacing the point that remains relatively fixed on it. But never simultaneously.
Yes, but for all practical purposes the top point of rotation moves relative to the rolling surface which adds a complexity which has to be taken into account and that is not so for the bottom point of rotation.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

marcio2003

  • Jr. Member
  • **
  • Posts: 69
Re: Vector Drawing - where to start?
« Reply #49 on: June 04, 2020, 01:14:26 am »
Hi,
... If I were to make 3D versions they could roll in any direction but that is currently outside of my manufacturing capability.
You really like to launch challenges, but, I will stop here.
if you want to talk about the application ..., so as not to escape the purpose of this forum.
I admire smart people. If you wish, use my email.
Best regards and take care with your health (covid-19).
Lazarus 2.0.10 Windows 10 64bits

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Vector Drawing - where to start?
« Reply #50 on: June 05, 2020, 11:33:23 am »
Moving on from the distraction :)    I'm looking at the drawing primitives and keep being stymied by the fact that there isn't a 'Circle'  which takes the arguments CentreX, CentreY and Diameter.

I appreciate that the bounding box Ellipse(X1,Y1,X2,Y2) is probably more flexible since it doesn't care if the 'ellipse' is the special case of a circle but it would be nice to call  Circle(X,Y,D).

To address this I've considered a procedure (which could even pass line_width, line_colour & fill_colour but lets not get ahead of ourselves!) but can't see a way to make it independent from an 'OnPaint' event.

I know the following code fragment isn't complete but I hope it better explains what I'm looking to do

Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. uses
  4.   Math;
  5.  
  6. {$R *.lfm}  
  7. procedure Circle(X,Y,D : Integer);
  8. const
  9.   S45 : single = sin(pi/4);
  10. var
  11.   X1,X2,Y1,Y2 : integer;
  12.   Rad : single;
  13.   dX  : single;
  14. begin
  15.   Rad := D / 2;
  16.   dX  := Rad * S45;
  17.   X1  := round(X-dX);
  18.   X2  := round(X+dX);
  19.   Y1  := round(Y-dX);
  20.   Y2  := round(Y+dX);
  21.  
  22. end;
  23.  
  24. procedure TForm1.PaperPaint(Sender: TObject);
  25. begin
  26.  
  27.   Paper.Canvas.Ellipse(X1,Y1,X2,Y2);
  28.  
  29. end;
  30.  

It may be that 'Circle' should be a Function rather than a Procedure   but it may also be that I have to have it as a sub-procedure within the OnPaint event - which defeats the 'independent' issue.

I'd appreciate the opinion of anyone 'in the know' !

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 13349
Re: Vector Drawing - where to start?
« Reply #51 on: June 05, 2020, 12:26:16 pm »
I do not understand what you want to achieve here. If you really are tired of typing a fourth parameter, here is a "Circle(ACanvas, X, Y, R)" procedure (I prefer radius over diameter because it avoids multiple divisions by 2); and the procedure should have a parameter for the Canvas to paint on so that it is generally usable:

Code: Pascal  [Select][+][-]
  1. procedure Circle(ACanvas: TCanvas; X, Y, R: Integer);
  2. begin
  3.   ACanvas.Ellipse(X-R, Y-R, X+R, Y+R);
  4. end;

I do not know why a "Circle" does not exist, maybe it's too straightforward. Or: if there were a "Circle" there should also be a "Square" (special case of "Rectangle"), or "Triangle" (special case of "Polygon")

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Vector Drawing - where to start?
« Reply #52 on: June 05, 2020, 01:05:21 pm »
I do not understand what you want to achieve here. If you really are tired of typing a fourth parameter, here is a "Circle(ACanvas, X, Y, R)" procedure (I prefer radius over diameter because it avoids multiple divisions by 2); and the procedure should have a parameter for the Canvas to paint on so that it is generally usable:

Code: Pascal  [Select][+][-]
  1. procedure Circle(ACanvas: TCanvas; X, Y, R: Integer);
  2. begin
  3.   ACanvas.Ellipse(X-R, Y-R, X+R, Y+R);
  4. end;
The addition of 'ACanvas : TCanvas' is the knowledge I was missing.  Does that mean (and I will test once I've sent this reply) that I could send   Circle(Paper, 250,250,50) - using the example from my previous code?

I prefer Diameter because I don't want to [Round] until the very last moment.

Quote from: wp
I do not know why a "Circle" does not exist, maybe it's too straightforward. Or: if there were a "Circle" there should also be a "Square" (special case of "Rectangle"), or "Triangle" (special case of "Polygon")
The fact that a Circle is just a special Ellipse is the reason I'm sure but there isn't an Ellipse which takes the Centre X Y - that's what I would like.

I've just realized that calculating X1,Y1 etc. from Centre XY is no more complex for an Ellipse than it is for a circle  :-[  so my use of sin(pi/4) is probably overkill and may even take longer than + or - the radius - or in the case of an ellipse each semi-axis.  Which is effectively what you have suggested in your code and why R could be more efficient than D ---  I sometimes don't appreciate that I've been pollaxed!   :-[   It's still the ACanvas that makes the difference though - as long as I can use 'Paper' or, in the default state, 'PaintBox1' as the ACanvas.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 13349
Re: Vector Drawing - where to start?
« Reply #53 on: June 05, 2020, 01:29:37 pm »
The addition of 'ACanvas : TCanvas' is the knowledge I was missing.  Does that mean (and I will test once I've sent this reply) that I could send   Circle(Paper, 250,250,50) - using the example from my previous code?
I assume "Paper" is a TPaintbox. Then this code does not work. The first parameter must be a TCanvas, and you must use Paper.Canvas. Having a TCanvas here has the advantage that the procedure is more versatile: it can be used for a Paintbox, a Panel, a Form, even a TBitmap.

I prefer Diameter because I don't want to [Round] until the very last moment.
OK, in the following modification the drawn diameter is off by 1 pixel (instead of 2 pixels in the former procedure) when the diameter is odd (or you should use a graphics library like BGRABitmap which supports floating point pixel coordinates)

Code: Pascal  [Select][+][-]
  1. procedure Circle(ACanvas: TCanvas; X, Y, D: Integer);
  2. var
  3.   X0, Y0: Integer;
  4. begin
  5.   X0 := X - D div 2;
  6.   Y0 := Y - D div 2;
  7.   ACanvas.Ellipse(X0, Y0, X0 + D, Y0 + D);
  8. end;
« Last Edit: June 05, 2020, 01:39:13 pm by wp »

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Vector Drawing - where to start?
« Reply #54 on: June 05, 2020, 02:27:14 pm »
The addition of 'ACanvas : TCanvas' is the knowledge I was missing.  Does that mean (and I will test once I've sent this reply) that I could send   Circle(Paper, 250,250,50) - using the example from my previous code?
I assume "Paper" is a TPaintbox. Then this code does not work. The first parameter must be a TCanvas, and you must use Paper.Canvas. Having a TCanvas here has the advantage that the procedure is more versatile: it can be used for a Paintbox, a Panel, a Form, even a TBitmap.

YES  -   I said that I would do some testing and that's the first thing I discovered - simple logic really - so working through the code it came to me :)  I'm essentially an empiricist.

Quote from: wp
Quote from: J-G
I prefer Diameter because I don't want to [Round] until the very last moment.
OK, in the following modification the drawn diameter is off by 1 pixel (instead of 2 pixels in the former procedure) when the diameter is odd.

Code: Pascal  [Select][+][-]
  1. procedure Circle(ACanvas: TCanvas; X, Y, D: Integer);
  2. var
  3.   X0, Y0: Integer;
  4. begin
  5.   X0 := X - D div 2;
  6.   Y0 := Y - D div 2;
  7.   ACanvas.Ellipse(X0, Y0, X0 + D, Y0 + D);
  8. end;

Being one pixel out instead of two seems to be 100% improvement    ;D

I have at least been able to make the [Circle] a stand alone procedure so thanks for the ACanvas info.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018