Separation of plane by line given two points

Rriskit

Given two points with x-y coordinates I have a line specified. Now I want to distinguish in an 2-d numpy array the points left to the line from those on the right.

The following code does the trick - but the double loop hurts my religious feelings (towards numpy). There must be a smarter way?

def myline(a_x,a_y,b_x,b_y):
start=np.zeros((100,100))
for x in range(100):
    for y in range(100):
        val= (b_x - a_x)*(y - a_y) - (x - a_x)*(b_y - a_y)
        if val<=0:
            start[x,y]=1
return start
Paul Panzer

This can be vectorized using ogrid:

x, y = np.ogrid[:100, :100]
start = (b_x - a_x)*(y - a_y) - (x - a_x)*(b_y - a_y) <= 0

This will give you a boolean mask. If you want some other dtype

start = start.astype(np.int)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line

From Dev

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line

From Dev

projecting points onto a plane given by a normal and a point

From Dev

Find the vertices of a line between two points with a given stroke width

From Dev

Javascript + svg, draw sinus (wave) line between two given points

From Dev

Extend line with given points

From Dev

orientate a 3d plane from 3 given points

From Dev

Interpolate new points between two given points

From Dev

Given two points (x1,y1) (x2,y2), how can I compute N different points evenly lying on the line between the given points

From Dev

How to compute two points, each on a line, equally distant from a given point?

From Dev

Check connection between two points on 2D plane

From Dev

how to calculate plane equation using three points and two vectors?

From Dev

How to calculate the points between two given points and given distance?

From Dev

How to draw vertical separation line between two text line android?

From Dev

How to draw vertical separation line between two text line android?

From Dev

Get x intercept given two points

From Dev

Finding center of a circle given two points and radius

From Dev

How to connect a line between 4 randomly placed points on a plane such that the line does not cross itself

From Dev

Given a set of points in the plane, find a (not necessarily convex) polygon of minimal area containing them

From Dev

How to generate a set of random points within a given (x,y) coordinates in an x-y plane?

From Dev

Join two endpoints of one line to two points in points table

From Dev

Extrapolate a line beyond two known points

From Dev

Drawing a line between two points using SceneKit

From Dev

Draw line between two points on console

From Dev

postgis distance between two points on a line

From Dev

Dividing two sets of points using a straight line

From Dev

R: draw a line between two points in ggplot

From Dev

How to Draw straignt Line between two Points?

From Dev

Distance between point and a line (from two points)

Related Related

  1. 1

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line

  2. 2

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line

  3. 3

    projecting points onto a plane given by a normal and a point

  4. 4

    Find the vertices of a line between two points with a given stroke width

  5. 5

    Javascript + svg, draw sinus (wave) line between two given points

  6. 6

    Extend line with given points

  7. 7

    orientate a 3d plane from 3 given points

  8. 8

    Interpolate new points between two given points

  9. 9

    Given two points (x1,y1) (x2,y2), how can I compute N different points evenly lying on the line between the given points

  10. 10

    How to compute two points, each on a line, equally distant from a given point?

  11. 11

    Check connection between two points on 2D plane

  12. 12

    how to calculate plane equation using three points and two vectors?

  13. 13

    How to calculate the points between two given points and given distance?

  14. 14

    How to draw vertical separation line between two text line android?

  15. 15

    How to draw vertical separation line between two text line android?

  16. 16

    Get x intercept given two points

  17. 17

    Finding center of a circle given two points and radius

  18. 18

    How to connect a line between 4 randomly placed points on a plane such that the line does not cross itself

  19. 19

    Given a set of points in the plane, find a (not necessarily convex) polygon of minimal area containing them

  20. 20

    How to generate a set of random points within a given (x,y) coordinates in an x-y plane?

  21. 21

    Join two endpoints of one line to two points in points table

  22. 22

    Extrapolate a line beyond two known points

  23. 23

    Drawing a line between two points using SceneKit

  24. 24

    Draw line between two points on console

  25. 25

    postgis distance between two points on a line

  26. 26

    Dividing two sets of points using a straight line

  27. 27

    R: draw a line between two points in ggplot

  28. 28

    How to Draw straignt Line between two Points?

  29. 29

    Distance between point and a line (from two points)

HotTag

Archive