Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / perpendicular to a curve...

Author
Message
iaretony
23
Years of Service
User Offline
Joined: 6th Jun 2003
Location:
Posted: 10th Jul 2003 02:03
Imagine a line paralell to the horizontal axis. Imagine a point, above and in between the original lines endpoints.

Now, translate the line and rotate it slightly.

How can I calculate where the upper point is now?

Tony
spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 10th Jul 2003 02:16
Can't picture what you are going on about. Any chance of a picture or a slightly better description.

R Tape loading error
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 10th Jul 2003 02:31
This is your skateboard question still, innit?

Work out the distance between the sprite origin and the centre of the skateboard. That should be very staight forward. If your skateboarder origin is initially 25,25 and your skateboard centre is 25,05 then the distance is 20. Save that as heightoffset#

Work out the angle of the skateboard as I said before:

SkateboardAngle# = atanfull(frontx-rearx,fronty-reary)

The angle of the normal to the skateboard is:

SkateNormal# = wrapvalue(SkateboardAngle#+90)

Work out the centre point of the skateboard:
centx# = (rearx+frontx)/2
centy# = (reary+fronty)/2

You should already know how far above the centre base point the sprites x,y is. This is the constant worked out above. So to find the origin of the sprite use some trig:

sprite_origin_x = centx + sin(SkateNormal#) * heightoffset#
sprite_origin_y = centy + cos(SkateNormal#) * heightoffset#

You might need to - the 90 rather than + it for the normal. Not sure. The theory is sound there though. Hope that helps. Sorry I didnt read your problem properly before.

Machine: P4 2200, 1GB RAM, GeForce4 64MB, Audigy Platinum
http://www.breakbeat-terrorism.co.uk
(It's not all about the coding)
iaretony
23
Years of Service
User Offline
Joined: 6th Jun 2003
Location:
Posted: 10th Jul 2003 08:19
Thanks!

That helps a TON!

A co-worker of mine mentioned that the tangent of an angle is perpendicular to that angle... Is this true?

If so, it seems like I should be able to use a tangent function to figure this out...

You're way will definatley work tho, and I'll use it immediatley!

Thanks Again!

Tony

Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 10th Jul 2003 15:22
I tangent is just a straight line with its gradient equal to the gradient at the point of a curve with which it intersects. So, if you imagine a circle and a line that is drawn outside it, and just touches it in one place. Where the line and circle meet, the gradients are the same, and the line becomes a (one of many) tangents to this curve.

As for tangents to an angle - I don't know. There are definitely loads of ways to solve that problem. Some are quicker, some are slowler. I know enough maths to solve most of the problems I have, but I definitely dont know it well enough to solve them in the most efficient way. That solution should be pretty quick though.

Machine: P4 2200, 1GB RAM, GeForce4 64MB, Audigy Platinum
http://www.breakbeat-terrorism.co.uk
(It's not all about the coding)
Herbie
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location:
Posted: 10th Jul 2003 17:08
The attached code may be what you're after. Sorry it's in java but the maths should be easy to port to DB. The line starts at x0,y0 ends at x1,y1, the point is a distance of h above the mid point of the line:

bx,by
| ^
| h
| |
x0,y0 ___________|___________x1,y1
ax,ay

Inputs: x0,y0,x1,y1 and h
Outputs: ax,ay, bx,by

The maths works by rotating the line by 90 degrees, translates it to the centre of the line and scales it to length h.

Note: the code avoids trig functions and if the distance l between x0,y0 and x1,y1 is known then the sqrt can be avoided as well

hope this helps,
H.

Login to post a reply

Server time is: 2026-07-18 07:31:22
Your offset time is: 2026-07-18 07:31:22