HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /Loci of squared distances
MathematicsHardHigh School (11–12)Coordinate Geometry

Loci of squared distances

You will write three functions for the loci of squared distances from two fixed points AAA and BBB. Points are pairs (x, y).

The idea. The rule PA2+PB2=sPA^2 + PB^2 = sPA2+PB2=s is the circle about the midpoint MMM with PM2=s−AB2/22PM^2 = \dfrac{s - AB^2/2}{2}PM2=2s−AB2/2​, when this is positive. The rule PA2−PB2=sPA^2 - PB^2 = sPA2−PB2=s is the line 2(xB−xA) x+2(yB−yA) y=s+∣B∣2−∣A∣22(x_B - x_A)\,x + 2(y_B - y_A)\,y = s + |B|^2 - |A|^22(xB​−xA​)x+2(yB​−yA​)y=s+∣B∣2−∣A∣2, where ∣A∣2=xA2+yA2|A|^2 = x_A^2 + y_A^2∣A∣2=xA2​+yA2​.

Your tasks.

  1. Finish sq_dist(P, Q). Return the square of the distance PQPQPQ.
  2. Finish sum_circle(A, B, s). Return (centre, radius), or None when PM2≤0PM^2 \le 0PM2≤0.
  3. Finish diff_line(A, B, s). Return (a, b, c) for the line ax+by=cax + by = cax+by=c.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, try A(0,0)A(0, 0)A(0,0), B(4,0)B(4, 0)B(4,0) and s=8s = 8s=8 in sum_circle. What is special about it?

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← Five areas and two radiiThe circle of Apollonius →
More onCoordinate Geometry

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. The equation of a locusLoci in the Coordinate Plane

More labs on this topic

  1. Polar points in PythonHard
  2. Turning the axesHard
  3. Shifting the originHard
  4. The circle of ApolloniusHard
All labs on this topic →