[SOLVED] complex math calculation in shell script needed
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Here is my situation:
I have a series of .plt files that are geared for a device that has it's xy origin at the lower left of the paper however some devices use the center of the paper as it's origin in a piped shell script how can I convert this file to a center origin plot file?
Here are some knowns: the existing file always Lower Left 0.0
the existing file max xy is the page upper right x.x
the desired output file must have it's 0.0 at the exact center of page (page size will vary).
Ideas: Based on the sample files included maybe use PU and PD as the triggers for inputs to be calculated as any other commands have nothing to do with coordinates.
These files are exactly the same on a small letter (page size will vary on job) size page one is center origin and the other is LL origin.
Maybe you should have a look at awk, which is much better in doing math than plain shell. You can call awk from your shell script. Since you do not know the maximum coordinate values in advance, you will have to store the input data in some way, because the maximum coordinate values can change with each new input record, invalidating the results of the former conversion. So you will need at least two processing steps, when the coordinate values of the corners are unknown. But in principle this task awk should be able to do the task.
I figured awk would do it but my math skills and ability to grasp calculations are limited (very limited)
Anyone out there feel like having a go at it?
I think you should try the following algorithm:
let awk match "PD<x> <y>" and "PU<x> <y>" and do the following:
x -= (maxx + minx)/2
y -= (maxy + miny)/2
I failed to mention the plotting device scans the paper size when loading paper so it knows what size paper is being used and therefore knows where the center 0.0 is based on it's scan.
This will move the specified box such, that its center is at the origin. In this case you do not need the minmax awk script and there is no need to temporarily store the input data.
In detail: If the origin is at the lower-left corner (0,0) and the width and height is (10000,7500), then the script will recalculate the coordinates such that the lower-left corner will be at (-5000,-3750) and the upper right one at (5000,3750).
The problem is the plotter knows the paper size in plotter units and where center 0,0 is but there is no way for the script to get these variables from the plotter. I'm unsure of why the paper size needs to be known at all. With coordinates being sent out in positive and negative xy's moving out from the starting point center 0,0 because the plotter knows where 0,0 is from it's paper scan. I must be missing something ...
If minmax is needed how would my cat temp.plt | xxx | xxx appear?
The original plt file is derived from a .ps or .pdf file can we sed/grep the "%%BoundingBox: 0 0 566 396" line before it gets processed into a plot file?
both files read
minx=200000
maxx=-200000
miny=200000
maxy=-200000
but the output files xy cordinates should have some negative x and y cordinates due to the fact that from 0.0 being in the center of the page in order to plot down in the bottom left quadrant the xy values for that quadrant will be negative values. Without negatives you are limited to the upper left quadrant only.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.