Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6560047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:24:35+00:00 2026-05-25T13:24:35+00:00

I need to change a triangle by replacing one of its points. However, I

  • 0

I need to change a triangle by replacing one of its points. However, I need to detect if doing so would cause the triangle to flip.

For example, the triangle defined by the points:

[(1.0,1.0), (2.0,3.0), (3.0,1.0)]

would look like this:

original triangle

If I change the third point from (3.0,1.0) to (1.0,2.0), it flips, as shown here:

flipped triangle

I’ve written a function that detects if a triangle is flipped by calculating the equation for the stationary points and detecting a sign difference in the y-intercept:

def would_flip(stationary, orig_third_point, candidate_third_point):

    #m = (y2-y1)/(x2-x1)
    slope = (stationary[1][3] - stationary[0][4]) / (stationary[1][0] - stationary[0][0])

    #y = mx + b
    #b = y-mx
    yint = stationary[0][5] - slope * stationary[0][0]

    orig_atline = slope * orig_third_point[0] + yint
    candidate_atline = slope * candidate_third_point[0] + yint

    if orig_atline > orig_third_point[1] and not(candidate_atline > candidate_third_point[1]) or \
        orig_atline < orig_third_point[1] and not(candidate_atline < candidate_third_point[1]):
        return True

    return False

This works nicely for most cases:

>>> would_flip([(1.0,1.0), (2.0,3.0)], (3.0,1.0), (1.0,2.0))
True
>>> would_flip([(1.0,1.0), (2.0,3.0)], (3.0,1.0), (4.0,2.0))
False

The problem I have is that if the stationary points are vertical, the slope is infinite:

>>> would_flip([(1.0,1.0), (1.0,3.0)], (3.0,1.0), (4.0,2.0))
ZeroDivisionError: float division by zero

Is there a better/faster way to detect a triangle flip that is robust to the stationary points being a vertical line? The fact that it’s written in python is not important. I will accept an answer that is just a formula or well-described technique.

EDIT: More information on what it means for a triangle to “flip”

Consider the four triangles below:

enter image description here

The top-left is the original triangle. The red line (same in all four) are the two stationary points. The rest of the three triangles replace the third point. The top-right and bottom-left triangles are not flipped, while the triangle in the bottom-right is flipped. Essentially, the triangle is “flipped” if the third point ends up on the opposite side of the imaginary line formed by the two stationary points.

UPDATE2: Working function using cross product:

def would_flip2(stationary, orig_third_point, candidate_third_point):
    vec1 = numpy.array([stationary[1][0] - stationary[0][0], stationary[1][1] - stationary[0][1], 0])
    vec2_orig = numpy.array([orig_third_point[0] - stationary[0][0], orig_third_point[1] - stationary[0][1], 0])
    vec2_candidate = numpy.array([candidate_third_point[0] - stationary[0][0], candidate_third_point[1] - stationary[0][1], 0])
    orig_direction = numpy.cross(vec1, vec2_orig)[2]
    candidate_direction = numpy.cross(vec1, vec2_candidate)[2]
    if orig_direction > 0 and not(candidate_direction > 0) or \
        orig_direction < 0 and not(candidate_direction < 0):
        return True
    return False
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:24:36+00:00Added an answer on May 25, 2026 at 1:24 pm

    Compute the cross-product of two vectors generated from your three points.
    If the direction of the cross product changes sign, the triangle has flipped.

    For example:

    Given [(1.0,1.0), (2.0,3.0), (3.0,1.0)]:
    Form two (3D) vectors

    (2-1,3-1,0) = (1,2,0) and (3-1,1-1,0) = (2,0,0)

    Take their cross product:

    (1,2,0) x (2,0,0) = (0,0,0-4) = (0,0,-4)
    

    Or, using numpy:

    import numpy as  np
    np.cross([1,2,0],[2,0,0])
    # array([ 0,  0, -4])
    

    While when given [(1.0,1.0), (2.0,3.0), (1.0,2.0)]: We form the two (3D) vectors:

    (2-1,3-1,0) = (1,2,0) and (1-1,2-1,0) = (0,1,0)

    And again take their cross product:

    np.cross([1,2,0],[0,1,0])
    # array([0, 0, 1])
    

    Since the vector (0,0,-4) points “down” and the vector (0,0,1) points “up”, the triangle has flipped.


    You don’t really need numpy for this. If you work out the math on paper, it turns out that if the points are given by (x1,y1), (x2,y2) and (x3,y3),
    then the key number in the cross product is given by

    (y2-y1)*(x2-x1) - (y3-y1)*(x2-x1)
    

    You just have to compute that value and watch for changes in its sign. (The three points are co-linear if and only if the expression above equals 0.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have database, and in one the tables I need change the values of
I need change or remove <title> tag in wordpress using plugin for example <title>
I have a database in SQL Server with its data. I need change a
I need change background of all text that have two spaces from the start
i need change color of SystemTray.ProgressIndicator color, how i can do it? I tried
I use Pjax with tutorial from http://railscasts.com/episodes/294-playing-with-pjax?view=comments I don't need change url and this
Need to change li position by clicking to move up or to move down.
I need to change a bitmap in the resources of a C# .NET 4.0
I need to change the DataTemplate for items in a ListBox depending on whether
I need to change the functionality of an application based on the executable name.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.