开发者

Find a point along an angled line

I'm trying to figure out how to find a point along a line (half way, to be precice).

I need this to put a particle emitter in the correct location to leave a smoke-trail after bullets.

I've got point A and point C. Point A is the barrel-muzzle, and point C is found using ray-cast. Now, in order to put the emitter in the righ开发者_如何学Ct location I need to find point D. How do one do this? I attached a picure to make it more visual.

No, I could not attach the picture, but here's a link.

Find a point along an angled line

Thanks in advance.

-Pimms


If your point is half way along a line between two points then you can just average their x and y co-ordinates to get the x and y for the midpoint (works in any number of dimensions).

If you want a point a certain proportion (ie 1/10th) along then you would do 1/10th of one point plus 9/10th of the other point.

In your example Point D is mid way between point A and C. This means the co-ordinates of D would be:

X = (0+10)/2 = 5 Y = (0+7)/2 = 3.5


Do I get you right? D is halfway between A and C ?

Solution: D = (A + C) / 2

or:

D.x = (A.x + C.x) / 2

D.y = (A.y + C.y) / 2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜