Nice. I think I'll file this one away as a possible basis for an orbital insertion routine.
SCREEN _NEWIMAGE(640, 480, 32)
WINDOW (-3.2, -2.4)-(3.2, 2.4)
FOR x = -3.2 TO 3.2 STEP .01 'The two arcs
PSET (x, ya(x)), -1
PSET (x, yb(x)), -1
NEXT
LowPoint = 2.4: HighPoint = -2.4
FOR y = 2.4 TO 0 STEP -0.01
FOR x = -3.2 TO 3.2 STEP 0.01
IF POINT(x, y) <> 0 AND y < LowPoint THEN LowPoint = y
NEXT
NEXT
FOR y = -2.4 TO 0 STEP 0.01
FOR x = -3.2 TO 3.2 STEP 0.01
IF POINT(x, y) <> 0 AND y > HighPoint THEN HighPoint = y
NEXT
NEXT
Midpoint = (HighPoint - LowPoint) / 2
CIRCLE (0, LowPoint + Midpoint / 2), Midpoint / 2
CIRCLE (0, HighPoint - Midpoint / 2), Midpoint / 2
CIRCLE (-2, -2), .1, &HFFFF0000 'one point
CIRCLE (1, 1.25), .1, &HFFFF0000 'second point
SLEEP
FUNCTION ya (x)
ya = -x ^ 2 / 4 - 1
END FUNCTION
FUNCTION yb (x)
yb = x ^ 2 / 4 + 1
END FUNCTION
*facepalm*
Not because it's wrong (you are supposed to intersect at the points), but I explained this more than once (not shown here). You could have described this without the circles ya know... Isn't that almost what you did above?
Make sure your method can start anywhere on curve one, and end anywhere on curve 2.
Here's the same problem with less unusable road:
Why wouldn't it work with any spot on curve one and end anywhere on curve 2? Unless you want to go from the same side to the same side? In that case, you just build a third circle to connect the other two and you use it as a direction changer.
include(`../test/linalg.txt'):
let(q1,-2):
let(f0,-2):
let(f1,1):
let(f2,-1/2):
let(q2,1):
let(g0,5/4):
let(g1,1/2):
let(g2,1/2):
let(d,
<
<1,[q1],[q1]^2,[q1]^3,[q1]^4,[q1]^5, [f0]>,
<1,[q2],[q2]^2,[q2]^3,[q2]^4,[q2]^5, [g0]>,
<0,1,2*[q1],3*[q1]^2,4*[q1]^3,5*[q1]^4, [f1]>,
<0,1,2*[q2],3*[q2]^2,4*[q2]^3,5*[q2]^4, [g1]>,
<0,0,2,3*2*[q1],4*3*[q1]^2,5*4*[q1]^3, [f2]/2>,
<0,0,2,3*2*[q2],4*3*[q2]^2,5*4*[q2]^3, [g2]/2>
>
):
let(r,syslinsolve([d])):
print_let(r,smooth(<for(<k,1,len([r]),1>,{elem(elem([r],[k]),len([r])+1),})>)) ,\n:
func(f6,{for(<k,1,6,1>,{elem([r],[k])*
- ^([k]-1)})}):
print_plot(f6,[q1]-1,[q2]+1,.1,60,40,1)
defsng a-z
const sw = 800
const sh = 600
declare SUB ccircle (x1, y1, r, col)
declare SUB cline (x1, y1, x2, y2, col)
declare FUNCTION yc (x)
declare FUNCTION yb (x)
declare FUNCTION ya (x)
SCREEN 12
CALL cline(0, 0, sw / 2, 0, 7)
CALL cline(0, 0, -sw / 2, 0, 7)
CALL cline(0, 0, 0, sh / 2, 7)
CALL cline(0, 0, 0, -sh / 2, 7)
zoom = 75
CALL ccircle(-2 * zoom, ya(-2) * zoom, 10, 14)
CALL ccircle(1 * zoom, yb(1) * zoom, 10, 15)
FOR x = -2.5 TO 2 STEP .01
CALL ccircle(x * zoom, ya(x) * zoom, 1, 14)
CALL ccircle(x * zoom, yb(x) * zoom, 1, 15)
'CALL ccircle(x * zoom, yc(x) * zoom, 1, 5)
a = -2/27
b = -7/36
c = 10/9
d = 11/27
y = a*x*x*x + b*x*x + c*x + d
pset (x*zoom + sw/2, sh/2 - y*zoom)
NEXT
sleep
system
END
FUNCTION ya (x)
ya = -x ^ 2 / 4 - 1
END FUNCTION
FUNCTION yb (x)
yb = x ^ 2 / 4 + 1
END FUNCTION
FUNCTION yc (x)
yc = x ' What should this be in order to smoothly join each curve?
END FUNCTION
SUB cline (x1, y1, x2, y2, col)
LINE (sw / 2 + x1, -y1 + sh / 2)-(sw / 2 + x2, -y2 + sh / 2), col
END SUB
SUB ccircle (x1, y1, r, col)
CIRCLE (sw / 2 + x1, -y1 + sh / 2), r, col
END SUB
Here is an interactive n-order bezier curve based on the iterative definition:
Nice thinking Steve, but theres a problem with that proposed curve in that it isnt smooth. In a car driving analogy, note that the steering wheel would have to jerk *instantly* when you transition from the line to the circle. A real road/car would forbid an instant jump like that, so you need to enter/exit the circle more gradually than a brutal tangent line. This is especially evident for smaller circles but true for all circles. That doesnt mean a part of the solution cant be line-like or circle-like though.Funny you trying to say derivative without saying derivative and giving away the solution (to who?). The fact that there isn't a closed expression for G means physics math will remain junk math.
Said another way, you want a curve to join at the points, yes. You also want the slope of the curve to match the slope of the road where it joins, check. Here's the subtle part: the slope of the slope of the curve must also match the slope of the slope of the road at the intersection points. This guarantees a jerk-free transition.
The fact that there isn't a closed expression for G means physics math will remain junk math.