1

Note: Although I want to accomplish this in java, I think the question is more suitable for this site since it is mostly mathematical.

I am in the following scenario. I want to draw a curve and I have the following points:

  • The starting point
  • The midpoint of the curve
  • The end point

And java allows me to create a curve from any of the following:

  • an arc with 2 points, the starting angle and the ending angle
  • an arc with center, radius, start angle and end angle
  • an arc with 3 points and the radius
  • Other curves of different types with 1 or 2 "control points", which I see that I do not have.

This Gimp screenshot shows roughly what I'm trying to achieve.

enter image description here

Edit: I clarify that I want to achieve the type of curves or arcs used in perspective to create circles. Next I leave a photo (it does not belong to me) to illustrate:

enter image description here

Edit 2:

One pattern I noticed, is that the curve is "enclosed" in a square formed by the first and last points. Below is a picture of an "ideal" curve:

enter image description here

What formula can I use to calculate any of those things?


Doing research, I found several questions that didn't serve my purpose (both here and on Stack Overflow) or I wasn't able to understand. Among what I found, I saw that you can get the center of an arc with bisectors as it says here, but I don't feel comfortable working with the long equations of the rect.

Viktor Vaughn
  • 19,278
Dante S.
  • 135
  • 2
    While there is a unique line going through any two points, curves going through three points are not unique. So, you need some parameter in order to determine the curve you want. – Michael Carey Jul 30 '23 at 23:18
  • If you mean the center of the (unique) circle passing through the three points, see several ways to calculate it under How to find the center of the circle that contains three given complex numbers? – dxiv Jul 30 '23 at 23:23
  • @MichaelCarey Maybe there is some parameter that I am forgetting. I can't imagine more than one curve passing through all three points and not moving randomly across the plane to pass through all three points. Sounds to me like there's only one in this case. But, I'm not a professional. – Dante S. Jul 30 '23 at 23:34
  • @dxiv My math is not that strong. I don't get to understand the symbology of the majority. Also, I'm working with integers in r2, not complex numbers. Thanks anyway and sorry. – Dante S. Jul 30 '23 at 23:38
  • 1
    @DanteS. "can't imagine more than one curve" $;-;$ Consider the $3$ points $(-1,0), (0,-1), (1, 0)$ then both the circle $x^2 + y^2 = 1$ and the parabola $y = x^2 - 1$ pass through those three points. If by curve you mean circle then say so in the question. Or maybe what you are really looking for is Bézier curves. – dxiv Jul 30 '23 at 23:39
  • @dxiv I just graphed it and you're right, I don't know why I didn't imagine that. Unfortunately, I don't know what extra parameter I'm missing or not thinking about. For the moment, I'll stick with the single circle, since I don't see a better way. Even so, I still don't understand the symbology of the response. – Dante S. Jul 30 '23 at 23:45
  • I look for anything that joins two points with a "non-line" – Dante S. Jul 30 '23 at 23:46
  • @DanteS. See several equations of the circle in Cartesian coordinates under Get the equation of a circle when given 3 points for example. But I suggest you first take a step back and think over what you are trying to achieve, because just 'joins two points with a "non-line"'' is not enough to describe or solve it. – dxiv Jul 30 '23 at 23:52
  • I read about that curve and it might be what I'm looking for, since perspective tries to "imitate" reality. But how do I calculate the control points? – Dante S. Jul 30 '23 at 23:54
  • One pattern I've noticed is that the curve is dedicated to "continuing" the previous line that appears in the second image, "going down" and approaching the second point, where it also forms the "continuation" of the line. In a moment I put an illustrative image. – Dante S. Jul 30 '23 at 23:59
  • 1
    The picture suggests that you want to draw an ellipse. Java can do that: https://chortle.ccsu.edu/java5/notes/chap36/ch36_5.html – Ethan Bolker Jul 31 '23 at 00:59
  • @EthanBolker Partly that's true, but I want to draw curves/arcs in general. Thanks the same! – Dante S. Jul 31 '23 at 13:06

2 Answers2

2

One way you can solve this problem is by using Bezier quadratic curves. The curve is given parametrically by

$ P(t) = P_1 (1 - t)^2 + 2 t (1 - t) P_2 + t^2 P_3 $

where $P_1$ is the starting point, $P_3$ is the end point, and $P_2$ is the point where the tangents to this (parabola) at $P_1$ and $P_3$ intersect.

You have $P_1$ and $P_3$ but you don't have $P_2$. Instead you have the midpoint of the curve at some $t \in [0, 1] $. Let's call this point $P_4$, so what you have is $P_1$ (start), $P_3$ (end) and $P_4$ (midpoint). What you don't have is $P_3$ and the value of $t = t_0$ at which $P(t_0) = P_4$.

Let your parameter be $t_0$, then

$ P(t_0) = P_1 (1 - t_0)^2 + 2 t_0 (1 - t_0) P_2 + t_0^2 P_3 = P_4 $

For example, we can take $t_0$ to be equal to $0.5$. Substituting this, we get

$ P_2 = \dfrac{ P_4 - P_1 (1 - t_0)^2 - t_0^2 P_3 }{2 t_0 (1 - t_0) } $

Since we've selected $t_0 = 0.5$ then

$ P_2 = \dfrac{ P_4 - 0.25 P_1 - 0.25 P_3}{0.5} = 2 P_4 - 0.5 P_1 - 0.5 P_3 $

Now that we have $P_2$, we can draw the curve $P(t)$ from $t = 0$ to $t = 1$.

Below are two examples of this method. The red points are $P_1$ through $P_4$ with $P_2$ being the calculated point and lies outside the curve while $P_4$ is the given midpoint.

enter image description here

enter image description here

Hosam Hajeer
  • 21,978
  • Luckily, I know the basics of parametric equations. I'm going to do an answer by passing the equations to formulas for x and y. Thank you so much! – Dante S. Jul 31 '23 at 13:23
1

Note: this answer is just passing the parametric equations from another answer into equations to get x and y separately. If this answer helped you, don't forget to support whoever did the original reasoning.

I also apologize for not using latex, since I don't know how to use it on this site, any editing or guidance is welcome.


We have the following parametric equation:

P2 = 2P4 − 0.5P1 − 0.5P3

We make explicit the points involved and resolve

(x, y) = 2(bx, by) - 0.5(ax, ay) - 0.5(cx, cy)
(x, y) = (2bx, 2by) - (0.5ax, 0.5ay) - (0.5cx, 0.5cy)
(x, y) = (2bx - 0.5ax - 0.5cx, 2by - 0.5ay - 0.5cy)

What results in, being k the axis with which the calculations are made

k = 2bk - 0.5ak - 0.5ck
Dante S.
  • 135