Link to home
Start Free TrialLog in
Avatar of shean85
shean85

asked on

Draw perpendicular lines

I need to draw perpendicular lines between two parallel lines .The perpendicular lines have to be drawn with constant distance between them .Two parallel lines could be straight lines or with slope. Known:  begin and end points for two parallel lines.


Thank you.
Avatar of caner_elci
caner_elci

Here I coded some part of what you want and I think you continue with this:

CPaintDC dc(this);
CPoint pt11( 10, 10 );
CPoint pt12( 100, 100 );
CPoint pt21( 10, 60 );
CPoint pt22( 100, 150 );

dc.MoveTo( pt11 );
dc.LineTo( pt12 );
dc.MoveTo( pt21 );
dc.LineTo( pt22 );

float m = (float)(pt12.y - pt11.y) / (float)(pt12.x - pt11.y);
float alpha = ::atanf( m );
float palpha = alpha + (3.14159f/2.0f);

CPoint basePt;

basePt.x = (pt12.x - pt11.x) / 2;
basePt.y = (pt12.y - pt11.y) / 2;

CPoint pbasePt;
int len = 50;

pbasePt.x = basePt.x + (int)(len * ::cos( palpha ));
pbasePt.y = basePt.y + (int)(len * ::sin( palpha ));

dc.MoveTo( basePt );
dc.LineTo( pbasePt );

ASKER CERTIFIED SOLUTION
Avatar of joghurt
joghurt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Though this sounds sarcastic :

Does (s)he have to know?
What's this site for?

(S)he asks for help, because (s)he doesn't know those your counted, or because (s)he is lost in even some radial-degree conversation, or because (s)he wants to have it instead of coding this thing...

Does not matter that much... so, please behave!
I just wanted to make things clear. I agree this site is for helping people but it would be nice to know whether he/she stuck in a particular problem in an almost complete program or if we have to explain things from 1+1 being 2.

And you know EE's policy about helping in school assignments. We SHOULDN'T write the whole thing instead of him/her. However, we will gladly help/him in solving any particular troubles or to outline the algorithm, etc.
Sure man, that's why I gave a hint, but not the whole code..

Cheers,

Caner