Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: Please help with GetCartesian Method Calculation
LeonVM
Newbie
Posts: 5
Permalink
Post Please help with GetCartesian Method Calculation
on: August 3, 2020, 18:25
Quote

Hi everyone
I am looking at the Arduino code and there is a method which calculates a return value for the getCartesian methods
one example is:
long calcX = long((pow(pageWidth, 2) - pow(bPos, 2) + pow(aPos, 2)) / (pageWidth*2));

I understand what all the functions in the equations do but I don't understand what the value means which is returned nor do I understand why the values such as page width, bPos, aPos are used.
I someone can give me a mathematical function to look up that would help a lot or if they can just explain the equation it would be appreciated as well.

All the best
Leon

LeonVM
Newbie
Posts: 5
Permalink
Post Re: Please help with GetCartesian Method Calculation
on: August 4, 2020, 19:05
Quote

I know now that this method simply returns the X coordinate of the gondola on a Cartesian plane, however I still am puzzled as to how the method of calculating this coordinate works.

sandy
Administrator
Posts: 1443
Permalink
sandy
Post Re: Please help with GetCartesian Method Calculation
on: August 9, 2020, 12:21
Quote

This http://2e5.com/plotter/V/design/ has got a great discussion about the maths behind these kinds of plotters. The most basic maths is simple pythagoras - treating the hanging V as two right-angle triangles.

To calculate the cartesian X position you need to know the width of the machine (called pageWidth in the code) and the lengths of the two strings (I call these aPos and bPos in the code).
https://github.com/euphy/polargraph_server_a1/blob/master/util.ino#L225

To calculate the cartesian Y position you need to know the cartesian X position (called cX in the code) and the length of either one of the two strings (I use a left-hand string in the code, and call it aPos).
https://github.com/euphy/polargraph_server_a1/blob/master/util.ino#L225

The code describes explicitly how this works and it'll make sense if you remember that pow(x, 2) is simply "x squared"). I'll try to put it into words.

Get X:
cartesianX = (pageWidth squared - bPos squared + aPos squared) / (pageWidth*2)

Get Y:
cartesianY = square root of (aPos squared - cartesianX squared)

sn

LeonVM
Newbie
Posts: 5
Permalink
Post Re: Please help with GetCartesian Method Calculation
on: August 9, 2020, 19:19
Quote

Okay thank you Sandy!
http://2e5.com/plotter/V/design/alphaLawOfCosines.png
From this formula can it then be assumed that when calculating calcX we are calculating c*cos(alpha) which is then the x coordinate?

and one more thing in the arduino code a variable startLengthMM is initialized with a value of 800, like startLengthMM = 800; without any references as to how this value came about how was this startlengthMM obtained?

it is used in the calculation of startLength with the equation
float startLength = ((float) startLengthMM / (float) mmPerRev) * (float) motorStepsPerRev;

Does the value of this startLengthMM matter?

Also why does the code use the pageWidth and not the machineWidth variable to calculate the position variables for the drawer?

Thanks for all the help

Pages: [1]
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.014 seconds.