# Good Math with Prototypes and Functions

**URL:** <https://forum.kirupa.com/t/good-math-with-prototypes-and-functions/21284>\
**Category:** flash\
**Created:** [May 19, 2003, 11:27pm UTC](https://forum.kirupa.com/t/good-math-with-prototypes-and-functions/21284 "2003-05-19T23:27:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jingman](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jingman/32/163_2.png) [@jingman](https://forum.kirupa.com/u/jingman)\
**Post date:** [May 19, 2003, 11:27pm UTC](https://forum.kirupa.com/t/good-math-with-prototypes-and-functions/21284/1 "2003-05-19T23:27:22Z")

</div>

So, right now when I want to find the distance between two points, I go:

dist = Math.sqrt((this\_x-that\_x)_(this\_x-that\_x)+(this\_y-that\_y)_(this\_y-that\_y))

BLECH! I don’t want to do that every time. So I want to make a nice little function that I can apply to an object. Problem is, I don’t know how to do this. Is it possible to end up with something as easy as:

Math.dist(thisclipname, thatclipname) ?

How do you guys set up functions that do bulky math and return nice clean numbers?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 11:41pm UTC](https://forum.kirupa.com/t/good-math-with-prototypes-and-functions/21284/2 "2003-05-19T23:41:18Z")

</div>

yeah, thats possible, ill give it a try

```auto

Math.dist = function(thismc,thatmc){
        result = Math.sqrt((thismc._x-thatmc._x)*(thismc._x-thatmc._x)+(thismc._y-thatmc._y)*(thismc._y-thatmc._y))
        return result;
}

```

now you can call it like:

Math.dist(thisclipname,thatclipname);

edit: tested, and edited some errors, now it works fine 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 12:30am UTC](https://forum.kirupa.com/t/good-math-with-prototypes-and-functions/21284/3 "2003-05-20T00:30:32Z")

</div>

hehe, yup that worked. Thought I tried exactly that, guess I mussed it. Thanks! Any other math shortcuts you can give me?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 9:13am UTC](https://forum.kirupa.com/t/good-math-with-prototypes-and-functions/21284/4 "2003-05-20T09:13:32Z")

</div>

nope, not that i know sorry 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 9:36am UTC](https://forum.kirupa.com/t/good-math-with-prototypes-and-functions/21284/5 "2003-05-20T09:36:58Z")

</div>

> _Originally posted by jingman_  
> **any other math shortcuts you can give me?**

are you looking for something specific? 🙂  
[http://proto.layer51.com/l.aspx?p=7](http://proto.layer51.com/l.aspx?p=7)
