2D cross line

Hi
I'm creating two lines in 2D space (build from 2 points or 1 point and direction) and i want to find cross of this two lines (if they aren't parallel) - is there any functionality in OCC to do it simply?

BR, Robert

Steven Diehl's picture

Hi Robert,

Search for geom2dapi_intercurvecurve in the forum.

Cheers,
Steven

directx11's picture

Thanks Steven, it works perfectly :). So, i have yet another question - i was trying to find, but didn't found any "nice" functionality to create line perpendicular (2D) to given one (and e.g. crossing given point). I managed to create such line using other calculations, but i was wondering about one function to do that - to make code more readable... is there any solution?

Steven Diehl's picture

Hmm, I don't know of an extra function to do this, but the "D1" function on a Geom2d_Curve returns the first derivative at a given parameter. If it's say (vx, vy), a perpendicular line would have (vy, -vx) as a direction. And the "D0" function would return the point for the same parameter. That's all you need for a perpendicular line there.

Steven

Pawel's picture

You can also try: gp_Lin2d::Normal

Pawel

Stephane Routelous's picture

if you want to be sure of the side, you can take the direction vector of the line and rotate it by PI/2 or -PI/2
to create a parallel line at a direction, I usually do :
(pseudocode, didn't check the method names)
gp_Pnt2d p = line.Position();
gp_Vec2d v = line.Direction();
gp_Vec2d v2 = v.Normalized();
v2.Rotate(Standard_PI/2.0);
v2.Scale(distance);
gp_Pnt2d p2 = p.Translated(v);
gp_Lin2d line2(p2,v);

HTH

Stephane Routelous's picture

should be gp_Pnt2d p2 = p.Translated(v2); of course ....

directx11's picture

Thanks for all answers :) - for my solution gp_Lin2d::Normal() is fine. I found also nice algorithm object GccAna_Lin2dTanPer(), which could also be used for that.