retrieving unknowns ( line graph ) - objective-c

The application I'm currently working on will provide the ability to take unknown values based on known values from a line graph. Here's the problem. The line graph will not exist theoretically. But the information provided and past data will be used to be able to find that unknown.
For example
x axis: known
y axis: unknown
plotted line graph: partially known
So in actuality we can draw a graph with the x, y axis and plot the line graph with what we actually know. So say our knowns are:
x axis: 10; y axis: 15; plot: 160 line
x axis: 12.7; y axis: 18; plot: 160 line
x axis: 15; y axis: 22; plot: 160 line
so if we drew this, anything between 10-15 we could detect the y axis by straight line up to the 160 line and then accross to the y axis to find the answer. Thus, more inputted information would eventually lead to every possibility between 1-100 to be answerable.
However, my issue is that in the sense of programatical logic I can't think of where to start. For instance, I'll have my known values such as;
x = 10; plot = 160; therefore y = 15
And could be said for the other examples, though how can I manipulate them numbers to find unknowns which I would find on the graph with a simple ruler?
So programatically it would look like
x = 13; plot = 160; therefore y = ?;
If anyone has much experience with line graphs or at least with the formulae to unknowns it would be great if you could provide me with some starting information or point me in the right direction. As of right now, I have no idea where to start.
edit;
I'm coming to the conclusion that I will have to interpolate between the two y known values for a ratio of x difference?
so for instance, an input of 13 would show as
input: 13; find closest less-than to that; find closest greater-than to that;
returns 12.7 and 15
now find a ratio difference between them
take their known y values
lowest: 18; highest: 22
now lerp(double lowest, double highest, double ratio of difference between xs
Do I appear to be taking the right path?

Polynomial Interpolation
y = y0+(y1+y0)*((x-x0)/(x1+x0));

Related

Get unitVector X Y Z values

i want to create lines on a surface using bunch of points, those lines must be in 5deg incremental
(In Catia using VBA)
here are the steps
Step:1 - first i will create lines using normal to surface option
Step:2 - then i measure the angle between normaltosurface line and xyPlane if the angle is near to 5deg mutiples number for ex if angle is 81.23deg
Step:3 - then i should create a line using point-direction option which is 80deg and if angle more than 82.5 and less than 87.5 then i should create a line using point-direction option which is 85deg to XYPlane
i need to get the X Y Z direction components (unit vectors in catia) which makes the angle between point-direction line and xyplane 5deg multiples like 80,85,90,95,100deg
the surface in the image is not actual surface
x y z components are unit vectors of line that i need to create
i know the angle, for that angle i need to find out the X Y Z unit vector values using VECTOR ROTATION IN 3D SPACE FORMULA
here is the image of that formula
here we know the value of theta using that we need to calculate X Y Z unit vector values
i need to this in VBA
I don't want to sound rude but are you looking for help with your code or are you giving assignment in hoping someone will give you solution for free ?
Anyway to get the direction vectors you can use something like this
Dim TempVariant As Variant
Dim aOrigin(2) As Variant
Dim aDirection(2) As Variant
Dim NewLine As HybridShapeLineNormal
Set NewLine = ShapeFactory.AddNewLineNormal(RefSurface, PointReference, 0, 1, VectorOrient)
Set TempVariant = NewLine
Call TempVariant.GetOrigin(aOrigin) 'get starting point x y z
Call TempVariant.GetDirection(aDirection) 'get vectors x y z
EDIT
If you want to deal with 3D rotation you can take a look at this excel.
It took me a while myself (about week) and I found this excel somewhere years ago which helped me ... therefore I'm unable to give credits for this.
Excel Euler angles

X axis vs Y axis Kotlin

I drew a perfect large square in canvas and then split that large square into 15x15 smaller squares.
Now I am moving a bitmap using an image along X and Y Axis. The bitmap is of same size as the smaller square.
It moves along X axis perfectly one square at a time. But it covers more than one square along Y axis. So I have to multiply by approximately 0.93 to get to the size of the smaller square. But the problem is that it gets more complicated with different devices cellphone vs tablet.
Does anybody know why Y axis is different from X axis?
Thank you in advance...
Most of the displays have a slightly different densities between the X and Y axis, using my device and running the following command:
adb shell dumpsys display
searching for "density", I got the result:
PhysicalDisplayInfo{1080 x 2280, 60.000004 fps, density 3.0, 442.451 x 438.727 dpi, secure true, appVsyncOffset 0, bufferDeadline 17666666}
Depending on how you're declaring your square that may be the cause.

Numpy polyfit .How to get exact fit for the data points provided

I have x,y data points.
Using these points, I am trying to create a function to fit 50 (y points)points to generate the corresponding x coordinates.
But in my plot, when I try to zoom, the plot, I can see the 50 points provided is fitting the curve, but data points are slightly deviating from the plot. There is a small change from data point (in the range on delta=.001) with respect to the line generated from the 50 points if I zoom.
How do I generate a perfect curve which fits the data points along with the 50 points provided.
please refer the screenshot of the code
To cover 50 points perfectly you need to increase the order of the polynom. So instead of polyfit(x, y, 10) try polyfit(x, y, 49) ?
See https://arachnoid.com/polysolve/
A "perfect" fit (one in which all the data points are matched) can often be gotten by setting the degree of the regression to the number of data pairs minus one.

Using matplotlib to plot a matrix with the third variable as source for a color map

Say you have the matrix given by three arrays, being:
x = N-dimensional array.
y = M-dimensional array.
And z is a set of "somewhat random" values from -0.3 to 0.3 in a NxM shape. I need to create a plot in which the x values are in the x-axis, y values are in the y-axis and using z as the source to indicate the intensity of each pixel with a color map.
So far, I have tried using
plt.contourf(x,y,z)
and the resulting plot is very nice for me (attached at the end of this paragraph), but a smoothing is automatically applied to the plot! I need to be able to distinguish the pixels and I cannot find a way to do it.
contourf result
I have also studied the possibility of using
ax.matshow(z)
in order to sucesfully see the pixels... but then I am struggling trying to personalize the x and y axis, since only the index of the pixel is shown (see below).
matshow result
Would you please give me some ideas? Thank you.
Without more information on your x,y data it's hard to know, but I would guess you are looking for pcolormesh.
plt.pcolormesh(x,y,z)
This would take the x and y data as input and hence shows the z data at the appropriate coordinates.
You can use imshow with the keyword interpolation='nearest'.
plt.imshow(z, interpolation='nearest')

How to find the point of collision between an irregular shape (built out of 3 circles) and a line

I'm making a program in which many weird shapes are drawn onto a canvas. Right now i'm trying to implement the last, and possebly hardest, one.
In this particular shape i need a way to find the location (on a 2d canvas) where the line hits the shape. The following image is an example of what i have right now.
The black dots are the points that a known to me (i also have the location of the center of the three open circles and the radius of these circles). Each of the three outer lines needs a line towards the center dot, ending at the point that it hits the circle. This shape can be turned 90, 180 or 270 degrees.
The shape should look something like the following:
If you need any other information, please ask me in the comments. I'm not very good at math so please be gentle, thanks!
If A and B are points forming a line, then you can describe any point on that line using coordinates:
x = t·Ax + (1−t)·Bx
y = t·Ay + (1−t)·By
0 ≤ t ≤ 1
You can also describe the circle with center M and radius r as
(x − Mx)2 + (y − My)2 = r2
So take the x and y from the equations of the line, and plug them into the equation of the circle. You obtain a quadratic equation in t. Its two solutions describe the two points of intersection between the line and circle. In your example, only one of them lies on the line segment, i.e. satisfies 0 ≤ t ≤ 1. The other describes a point on the extension of the segment past its endpoint. Take the correct value for t back to the equations of the line, and you obtain the x and y coordinates of the point of intersection.
If you don't know up front which circle you want to intersect with a given line, then intersect all three and choose the most appropriate point afterwards. Probably that is the point closest to the outside starting point of the line segment. The same goes in cases where both points of intersection lie on the segment.