[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Stupid question vx vy

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 2

File: halp.png (10KB, 1138x724px) Image search: [Google]
halp.png
10KB, 1138x724px
Hello, I'm doing a program and I have been stuck for a while.
Imagine I want to move the blue dot to the red dot through the smallest path, d, by clicking on the screen (red dot).
I tried many different ways but the blue dot won't ever go through the coordinates I pressed, it seems to act kinda randomly.

How do I make it move to where I pressed?
Basically I want to get vx and vy.
Using java.

>Inb4 >>>/g/
>>
I literally have not the foggiest idea.

Try asking /g/ in the programming general.
>>
>>7664657
babby's first rpg walk code
>>
If you're really set against /g/ then stack overflow could be helpful
>>
Piggybacking on the stupid question thread:

Do secondary alcohol molecules form hydrogen bonds with other molecules of the same compound? Or only primary alcohols do that?
>>
>>7664657
if you have the starting point A and the ending point B, then you can describe the line which A and B belong to with the equations: xt=(1-t)*xA+t*xB and yt=(1-t)yA+t*yB, given parameter t.

with d=|AB|, dx=xB-xA, dy=yB-yA, if your desired total speed is v, then vx=v*dx/d and vy=v*dy/d

you don't even need vx and vy to move the blue dot, because by calculating dt=v/d, you can calculate the next position of the dot by putting t'=t+dt and substituting it in the equations above.

this is called linear interpolation, fun stuff, i may also have made some errors here, anyone who can correct me feel free to do so
>>
>>7664782
I think it might be a problem with my code then. The blue dot does not go exactly to where I want in the first click, same direction and constant speed but not the exact coordinates and then if I click in the same spot ,for example, it will switch directions each click.
>>
>>7664657
V E C T O R S
E
C
T
O
R
S
>>
>codemonkeys are stupid
>/sci/ is the smartest board

shake my head to be honest friend
>>
>>7664657

#define SOME_EPSILON (float)0.000001f
#define SOME_SCALER (float)0.5f

class Vector2
{
public:
float x, y;
Vector2() : x(0), y(0) {}
Vector2( const float& X, const float& Y ) : x(X), y(Y) {}
Vector2( const Vector2& v ) : x(v.x), y(v.y) {}
void set( const float& X, const float& Y ) { x=X; y=Y; }
const Vector2& operator + ( const Vector2&a, const Vector2& b ) { return Vector2( a.x + b.x, a.y + b.y ); }
const Vector2& operator - (const Vector2& a, const Vector2& b) { return Vector2( a.x-b.x, a.y-b.y ); }
const Vector2 &operator += (const Vector2 &v) { x += v.x; y += v.y; return *this; }
const Vector2 &operator *= (const float &f) { x *= f; y *= f; return *this; }
void normalize() { float n =1.f / Length(); x *= n; y *= n; z *= n; }
float length() { return (float)sqrt(x*x + y*y + z*z); }
const bool operator == (const Vector2 &a, const Vector2 &b) {
if (fabs(a.x - b.x) < SOME_EPSILON) {
if (fabs(a.y - b.y) < SOME_EPSILON) {
return true;
}
}
return false;
}
const bool operator != (const Vector2 &a, const Vector2 &b) {
return !(a == b); }
}

inside your program...

Vector2 blue_position( blue_x, blue_y );
Vector2 red_position( red_x, red_y );
Vector2 direction = red_position - blue_position;
direction.normalize();
direction *= SOME_SCALER;
while( blue_position != red_position) {
blue_position += direction;
}
>>
>>7668076
EDIT: the z's from normalize() and length() need to be removed since these are 2d vectors
>>
>>7664657
Subtract the bluedot pos from the reddot pos then get arctangent of that then use sin and cos with linear interpolation and add that back to bluedot
>>
File: sci's programming.png (289KB, 604x1640px) Image search: [Google]
sci's programming.png
289KB, 604x1640px
>>7664657
>Using java.

>>>/g/tfo
Thread posts: 13
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.