Jump to content
  • Advertisement

Archived

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

Magallo

Math problems

This topic is 6540 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

Hi guys, I know that this s a stupid question and that I studied these stuff when I was at school but I really need your supper and help. I have a problem: I have a segment from P1 and P2 and I would like to draw a little segment from the middle of the segment that is perpendicular to it. So I have to find two point: the middle point of the segment that is (P1.X + P2.X)/2 and (P1.Y + P2.Y)/2 and the other point that is along the perpendicular of the segment. I really don''t know how to find it. Please help

Share this post


Link to post
Share on other sites
Advertisement
hi,

you can use the fact that the dot product of 2 perpendicular vectors is 0

let p4 the point in the middle of segment p1p2 and p3 the point you are looking for:

p1p2.p3p4=0

((p2.x-p1.x)*(p4.x-p3.x))+((p2.y-p1.y)*(p4.y-p3.y))=0

fix a value to p3.x and that''s it!

lunasol

Share this post


Link to post
Share on other sites
In 2D you can rotate a vector by 90 degrees with the following formula:

x'' = -y
y'' = x

Now take your line segment (P2-P1), rotate it 90 degrees and then scale it to the length you want it to be.

- WitchLord

Share this post


Link to post
Share on other sites
Just a question Witchlord...

It works fine but obviously the perpendiculat has the same lenght of the line that I draw. How can I scale it to the lenght I want it to be ?

Share this post


Link to post
Share on other sites
to scale a normal vector:

nx is your normal x value
ny is your normal y value
nz is your normal z value
scale is the length you want it to be

length = scale / sqrt(nx*nx+ny*ny+nz*nz);
nx *= length;
ny *= length;
nz *= length;

for 2d you can cut alot of this out:

length = scale / sqrt(nx*nx+ny*ny);
nx *= length;
ny *= length;




"Like all good things, it starts with a monkey.."

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!