7
\$\begingroup\$

Task

Write a program or function that will determine if a point in 3D space lies on a 2D parabolic curve.


Input

3 points in 3D space

  • vertex of a 2D parabolic curve

  • arbitrary point on the curve

  • arbitrary point in space

Input may be taken in any form (string, array, etc.) provided no other data is passed.


You may assume

  • the axis of a parabola will be parallel to the z axis

  • the vertex of a parabola has the maximal z value

  • parabolae will never degenerate

  • point values will be whole numbers that are ≥ -100 and ≤ 100


Output

A truthy/falsey value representing whether the third point given lies on the parabolic curve of the first two points.


Examples

Input:

(2, 1, 3)
(1, 0, 1)
(4, 3, -5)

Output:

1

Input:

(16, 7, -4)
(-5, 1, -7)
(20, 6, -4)

Output:

0

Walkthrough (Example #1)

  1. Find a third point on the curve. To do this, mirror the arbitrary point (on the curve) over the vertex. Here is a visual (each blue line is √6 units):

  2. Find the parabolic curve between the three. This is easiest on a 2D plane. Here is the 3D graph, translated to a 2D graph (each blue line is √6 units):

  3. Graph the third given point and solve.

Wheat Wizard
103k23 gold badges299 silver badges697 bronze badges
asked Feb 12, 2016 at 4:17
\$\endgroup\$
5
  • \$\begingroup\$ I'll have a Jelly answer in five minutes. \$\endgroup\$ Commented Feb 12, 2016 at 4:23
  • 3
    \$\begingroup\$ @ThomasKwa its been 6 minutes. \$\endgroup\$ Commented Feb 12, 2016 at 4:24
  • \$\begingroup\$ @Maltysen Sorry for the disappointment; I think a feature may have changed. \$\endgroup\$ Commented Feb 12, 2016 at 4:30
  • \$\begingroup\$ by "axis of the parabola is parallel to z-axis" you mean that the plane containing the parabola is parallel to the z-axis? \$\endgroup\$ Commented Feb 12, 2016 at 7:57
  • \$\begingroup\$ @Liam both the plane containing the parabola, and also its plane of symmetry. The intersection of those two planes defines the axis. \$\endgroup\$ Commented Feb 12, 2016 at 13:06

1 Answer 1

3
\$\begingroup\$

Jelly, (削除) 13 (削除ここまで) 11 bytes

_÷/μḢ2=A;$P

The input format is a bit strange; it takes P1 as the second argument, and (P3,P2) as the first argument, where each point is expressed in the form ((x+yj),z).

We first normalize the points so that the vertex is on the origin, and then make sure that P1 and P2 are on the same line, and also that the ratio of their z distances is equal to the ratio of their x distances.

_÷/ Helper link. Inputs: (P3,P2) on left, P1 on right.
_ Subtract right from left. (P3-P1,P2-P1). 
 ÷/ Fold division. (P3-P1)/(P2-P1). P2-P1 is nonzero in both x+yi and z.
 μ Push the chain onto the stack, and start a new monadic link.
 Ḣ2=A;$P Hook; main link. Calculates whether w2 = a and a is nonnegative.
 Input: The result of the helper link. Call it [w,a].
 Ḣ2 Pop w and square it. Now the list is [a].
 A,$ Concatenate a to its absolute value.
 = Fork; is w equal to [a,abs(a)]? Returns 2 element list of 0 or 1
 P Product; that is, true if w was equal to both a and abs(a).

Try it here.

answered Feb 12, 2016 at 4:49
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.