Cartesian Points on Elliptic Curves in sage - sage

I just want to sample cartesian points from an elliptic curve in $(x,y)$ form. Given one of x or y, I want to be able to calculate the other's possibilities.
Examples: I have EllipticCurve('11a') and I want to know where it intersects the x-axis in (x,y) coordinates. What about where the curve intersects x=5? Or where it intersects y=3?
Can somebody assist me in doing this?

You just need to solve a polynomial equation in one variable. The factor function, or the .roots method of polynomials can do that for you.

Related

Perspective projection of rational bezier

I need a method to project 3d conics to 2d. None of the articles tell how to do this with rational beziers. Another thing I need a method for is moving 3d or 2d conics to 4d or 3d respectively (as in a reverse projection). I read somewhere that rational beziers can be split by moving them to a higher dimension and splitting the resulting non-rational curve with de Casteljau and then moving back. I seem to recall that perspective projection of conic beziers can be represented exactly with conic beziers, and that it may involve splitting into several curves. I don't understand any of the articles on any site on beziers.
Since there aren't any better answers, here's what I can offer off the top of my head...
Perspective transformation can change parabolas into ellipses or hyperbolas and vice-versa, so even though P0, P1, and P2 can be directly mapped, the weights will change.
Assuming a conic with weights (1,w,1), however, the distance along the line from (P0+P2)/2 to P1 at which it intersects the curve is simply related to the weight w, and that lets you find the new weight as follows:
Map P0, P1, and P2 to P0', P1', P2'
Calculate the midpoint M' = (P1'+P2')/2
Inverse map M' to M, and calculate the intersection point I of the line M-P1 with the original curve.
Map the intersection point I to I', to get the point at which the new curve should intersect M'-P1'
Calculate the new weight w' from the position of the intersection I'. The curve gets to I at t=0.5, so w' = (M'-I')/(P1'-I'). Note that this division makes sense, because the vectors being divided are collinear. You can divide their lengths or just the largest coordinate.
If you expand out all the steps, I'm sure there are ways to simplify this procedure.

how to get coordinates of intersection of line and curve by clicking on intersected points?

I have one non-linear (this curve is plotted using twenty coordiantes) and one linear curve (knowing equation). After plotting them I need to find the point of intersection. May be by clicking on points of intersection.
data<-read.csv(file.choose(),header=T,sep=",")
x<-seq(2.2,22,by=10)
plot(x,data[4]) ##plotting curve##
lines(x,data[4) ## joining points to get curve##
x1<-(0,max(x)
y1<-(0,max(x)*5+45) ## trying to define straight line##
lines(x1,y1)

Finding the coordinates of points from distance matrix

I have a set of points (with unknow coordinates) and the distance matrix. I need to find the coordinates of these points in order to plot them and show the solution of my algorithm.
I can set one of these points in the coordinate (0,0) to simpify, and find the others. Can anyone tell me if it's possible to find the coordinates of the other points, and if yes, how?
Thanks in advance!
EDIT
Forgot to say that I need the coordinates on x-y only
The answers based on angles are cumbersome to implement and can't be easily generalized to data in higher dimensions. A better approach is that mentioned in my and WimC's answers here: given the distance matrix D(i, j), define
M(i, j) = 0.5*(D(1, j)^2 + D(i, 1)^2 - D(i, j)^2)
which should be a positive semi-definite matrix with rank equal to the minimal Euclidean dimension k in which the points can be embedded. The coordinates of the points can then be obtained from the k eigenvectors v(i) of M corresponding to non-zero eigenvalues q(i): place the vectors sqrt(q(i))*v(i) as columns in an n x k matrix X; then each row of X is a point. In other words, sqrt(q(i))*v(i) gives the ith component of all of the points.
The eigenvalues and eigenvectors of a matrix can be obtained easily in most programming languages (e.g., using GSL in C/C++, using the built-in function eig in Matlab, using Numpy in Python, etc.)
Note that this particular method always places the first point at the origin, but any rotation, reflection, or translation of the points will also satisfy the original distance matrix.
Step 1, arbitrarily assign one point P1 as (0,0).
Step 2, arbitrarily assign one point P2 along the positive x axis. (0, Dp1p2)
Step 3, find a point P3 such that
Dp1p2 ~= Dp1p3+Dp2p3
Dp1p3 ~= Dp1p2+Dp2p3
Dp2p3 ~= Dp1p3+Dp1p2
and set that point in the "positive" y domain (if it meets any of these criteria, the point should be placed on the P1P2 axis).
Use the cosine law to determine the distance:
cos (A) = (Dp1p2^2 + Dp1p3^2 - Dp2p3^2)/(2*Dp1p2* Dp1p3)
P3 = (Dp1p3 * cos (A), Dp1p3 * sin(A))
You have now successfully built an orthonormal space and placed three points in that space.
Step 4: To determine all the other points, repeat step 3, to give you a tentative y coordinate.
(Xn, Yn).
Compare the distance {(Xn, Yn), (X3, Y3)} to Dp3pn in your matrix. If it is identical, you have successfully identified the coordinate for point n. Otherwise, the point n is at (Xn, -Yn).
Note there is an alternative to step 4, but it is too much math for a Saturday afternoon
If for points p, q, and r you have pq, qr, and rp in your matrix, you have a triangle.
Wherever you have a triangle in your matrix you can compute one of two solutions for that triangle (independent of a euclidean transform of the triangle on the plane). That is, for each triangle you compute, it's mirror image is also a triangle that satisfies the distance constraints on p, q, and r. The fact that there are two solutions even for a triangle leads to the chirality problem: You have to choose the chirality (orientation) of each triangle, and not all choices may lead to a feasible solution to the problem.
Nevertheless, I have some suggestions. If the number entries is small, consider using simulated annealing. You could incorporate chirality into the annealing step. This will be slow for large systems, and it may not converge to a perfect solution, but for some problems it's the best you and do.
The second suggestion will not give you a perfect solution, but it will distribute the error: the method of least squares. In your case the objective function will be the error between the distances in your matrix, and actual distances between your points.
This is a math problem. To derive coordinate matrix X only given by its distance matrix.
However there is an efficient solution to this -- Multidimensional Scaling, that do some linear algebra. Simply put, it requires a pairwise Euclidean distance matrix D, and the output is the estimated coordinate Y (perhaps rotated), which is a proximation to X. For programming reason, just use SciKit.manifold.MDS in Python.
The "eigenvector" method given by the favourite replies above is very general and automatically outputs a set of coordinates as the OP requested, however I noticed that that algorithm does not even ask for a desired orientation (rotation angle) for the frame of the output points, the algorithm chooses that orientation all by itself!
People who use it might want to know at what angle the frame will be tipped before hand so I found an equation which gives the answer for the case of up to three input points, however I have not had time to generalize it to n-points and hope someone will do that and add it to this discussion. Here are the three angles the output sides will form with the x-axis as a function of the input side lengths:
angle side a = arcsin(sqrt(((c+b+a)*(c+b-a)*(c-b+a)*(-c+b+a)*(c^2-b^2)^2)/(a^4*((c^2+b^2-a^2)^2+(c^2-b^2)^2))))*180/Pi/2
angle side b = arcsin(sqrt(((c+b+a)*(c+b-a)*(c-b+a)*(-c+b+a)*(c^2+b^2-a^2)^2)/(4*b^4*((c^2+b^2-a^2)^2+(c^2-b^2)^2))))*180/Pi/2
angle side c = arcsin(sqrt(((c+b+a)*(c+b-a)*(c-b+a)*(-c+b+a)*(c^2+b^2-a^2)^2)/(4*c^4*((c^2+b^2-a^2)^2+(c^2-b^2)^2))))*180/Pi/2
Those equations also lead directly to a solution to the OP's problem of finding the coordinates for each point because: the side lengths are already given from the OP as the input, and my equations give the slope of each side versus the x-axis of the solution, thus revealing the vector for each side of the polygon answer, and summing those sides through vector addition up to a desired vertex will produce the coordinate of that vertex. So if anyone can extend my angle equations to handling beyond three input lengths (but I note: that might be impossible?), it might be a very fast way to the general solution of the OP's question, since slow parts of the algorithms that people gave above like "least square fitting" or "matrix equation solving" might be avoidable.

How to find the points of intersection between a line and ellipse in R

I would like to find the points of intersection between an ellipse and a line
If using the example (ignoring a few un-needed arguments) from the dataEllipse function from the car package i.e.
x <- dataEllipse(Prestige$income, Prestige$education, levels=0.95, lty=2)
and say you have the horizontal line
abline(14,0)
how do you find the two points of intersection between the line and the ellipse
I know you can get the data that makes the ellipse from just looking at x, however I would like to get the exact points of intersection.
The equation of an ellipse is given by:
x^2/a+y^2/b=1, and the equation of a line by cx+d=y (where a,b,c,d coefficients).
You can substitute y in the ellipse equation. Then the goal is to find the solution of f(x)=0. You can use some method like bisection to solve such a problem.
Check this out:
http://www.math.wichita.edu/~cma/stat774/ch2.pdf
I bet there's a curve-fitting method that can get the foci and axis lengths of your ellipse from the set of x-y coords, but it looks tough: http://www.site.uottawa.ca/~mstoj075/Publications_files/EllipseFit.pdf . You might get a "good enough" answer by using splinefun on your set of x-y coordinate data and following the answers in The intersection point between a spline and a line

how can i construct the bezier curve if i only have points in x axis?

how can i construct the bezier curve if i only have points in x axis?can i do this act or need points for x and y axes related to t parameter?
i want constructe a bezier curve(from degree N)in a given interval and known point in that interval(that are random), but i have points only in x axes!!Whether this is feasible?
Can you specify the slopes at the end-points. You will need to do this for any bezier curve, The fact that the data points are on the x-axis is irrelevant.

Resources