Thu, 09/17/2009 - 16:15
Forums:
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
Thu, 09/17/2009 - 16:26
Hi Robert,
Search for geom2dapi_intercurvecurve in the forum.
Cheers,
Steven
Thu, 09/17/2009 - 17:33
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?
Thu, 09/17/2009 - 17:53
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
Thu, 09/17/2009 - 18:00
You can also try: gp_Lin2d::Normal
Pawel
Thu, 09/17/2009 - 18:12
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
Thu, 09/17/2009 - 18:13
should be gp_Pnt2d p2 = p.Translated(v2); of course ....
Fri, 09/18/2009 - 13:27
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.