🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Math problems

Started by
4 comments, last by Magallo 24 years ago
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
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
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks a lot guys!!!!

You are blood fo me
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 ?

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.."
"Like all good things, it starts with a monkey.."

This topic is closed to new replies.

Advertisement