Archived

This topic is now archived and is closed to further replies.

simple 2d computations

This topic is 6640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, the problem that I see with number 1 is that you are dealing with a line _segment_. A couple floating point multiplies and subtracts (using Cramer's rule) and you can have an X coordinate of the intersection, then a quick bounds check on the line segment to see if that intersection is actually on the segment.

As for number 2, you can follow up number with the calculation for the Y coordinate as well with little effort.

For number 3, I assume you mean on which side of a line, because if you really mean a ray then you must explain what result you want if the point lies on the line containing the ray but not the ray itself. If you do in fact mean a line, a quick check to see where the line is at the point's X coordinate (must have it's equation in y = mx + b form) will yield the answer.

I can type some quick code up for you if you need it. Just email me at: splat@bancroftpress.com

Share this post


Link to post
Share on other sites
all you need to do to determine if a line and a ray CAN cross is check to see if they are parallel, which is just checking the slopes against one another, with of course a special case for infinite slopes.

for rays, you can also use parametric equations to simplify things.

x=x0+cos(theta)*t
y=y0+sin(theta)*t
t>=0

where theta is the angle in which the ray is going and x0,y0 is the start of the ray.

to determine whether a point is on or not on the ray, you take either the x or y and solve for t, if t<0, then the point is NOT on the ray, otherwise it is. since you only care about whether or not it's negative, you dont actually have to perform the division, you can just compare things to 0

Share this post


Link to post
Share on other sites
Hi, i need to know fastest way of doing these calculations (all is 2d planar):

1) Check if ray can intersect line segment (without finding intersection point for speed reasons)
Ray defined by starting point and cross point, and line segment defined by two points.

2) find intersection between ray and line segment

3) find on which side of ray (left or right) point lies

------------------
FlyFire/CodeX
http://codexorg.webjump.com

Share this post


Link to post
Share on other sites