Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Calculating a point a specified distance away from another poin

Status
Not open for further replies.

HerbertMunch

New Member
Im utterly sick of eagle, so ive started work on a pcb editor and have now got side tracked on the graphics editor element of the project.

Does anyone know how to calculate a point that is a specified distance away from another along a line?

Ive defined a straight line class in c# that can encapsulate all the maths and its all working nicely appart from this.

In the rest of the class, i use y=mx+c and pyt. a² = b² + c² forumulas to calculate length, x from y, y from x etc.

Everything on the web talks about finding the distance between two points, but I allready know how to do that, i want to find a point, given a distance!

Many thanks,
Chris:)
 
Chris,
That is a lot of work to do by yourself.

If you want to go that route join an open source project to do the same. There should be a few out there.
You may want to look at the gEDA project.

The gEDA project is working on producing a full GPL‘d suite of EDA (Electronic Design Automation) tools. These tools are used for electrical circuit design, schematic capture, simulation, prototyping, and production. Currently, the gEDA project offers a mature suite of free software applications for electronics design, including schematic capture, attribute management, bill of materials (BOM) generation, netlisting into over 20 netlist formats, analog and digital simulation, and printed circuit board (PCB) layout.

For what it is worth you need a point and a direction to find the second point.
 
This file arcline.txt is an OLD Old old program I wrote for GWBASIC or BASICA. It plots an arc across 3 points on the screen. It may plot smooth contours from points 2,3&4 then points 3,4,5 averaging the first part of an arc with the last part of the previous arc. Are you confused yet?
Anyway, what you want is in there. You just have to find it. If you have GWBASIC or BASICA, you can load it as a txt file and run it and see how it works. If you modify it, save it as a BAS file.
If you don’t have GWBASIC or BASICA, you can get it online and full manual or I can ZIP them for you.
 

Attachments

  • Arcline.txt
    3.6 KB · Views: 374
Last edited:
WITH NUM LOCK ON MOVE PIXEL WITH 1 - 9. 5 LETS YOU ENTER A POINT 1,2,3 OR 4
IF YOU ENTER 4,IT PLOTS ARC USING THE LAST TWO POINTS AS 1 & 2

I was wrong, it doesn’t plot an average, just more arcs. This is a better copy because the input prompt was confusing.
In GWBASIC, CTRL > Break stops the program and SYSTEM, Enter gets you back to Windows. It may run in Q-BASIC as well.
 

Attachments

  • Arcline.txt
    3.6 KB · Views: 357
HerbertMunch said:
Everything on the web talks about finding the distance between two points, but I allready know how to do that, i want to find a point, given a distance!

Many thanks,
Chris:)

You would also need to know direction (angle) from your starting point in order to find a new point.

Your new point would simply be:

Xnew = Xorig + dist*sin(angle)
Ynew = Yorig + dist*cos(angle)
 
phalanx said:
You would also need to know direction (angle) from your starting point in order to find a new point.

Your new point would simply be:

Xnew = Xorig + dist*sin(angle)
Ynew = Yorig + dist*cos(angle)

Nice one mate. Thanks very much.

I have a gradient (y=Mx+c). How would i go about turning M into degrees?

Many thanks.:)
 
HerbertMunch said:
Nice one mate. Thanks very much.

I have a gradient (y=Mx+c). How would i go about turning M into degrees?

Many thanks.:)

M is your slope which is defined as your rise over your run: ΔY/ΔX

The tangent of an angle is calulated by dividing the rise by the run so if you take the inverse tangent of your slope, you will get the angle: tan-1(M) = angle.

For instance, if your line is defined as y=x+4, your slope is "1" and the tan-1(1)= 45°

Make sure you know if your code is working in degrees or radians. If need be you can convert between them.
 
Last edited:
phalanx said:
M is your slope which is defined as your rise over your run: ΔY/ΔX

The tangent of an angle is calulated by dividing the rise by the run so if you take the inverse tangent of your slope, you will get the angle: tan-1(M) = angle.

For instance, if your line is defined as y=x+4, your slope is "1" and the tan-1(1)= 45°

Make sure you know if your code is working in degrees or radians. If need be you can convert between them.

thanks very much. that works perfectly!:)
 
Converting TAN to angle in order to get SIN and COS is not the best way to do it because you need more calculation and will get higher error.
This is better
SIN=SQRT(1/(1+1/M^2))
COS=SQRT(1/(1+M^2))
 
Sick of Eagle ? I can see why :D but I am still using it - I don't know about anything better that is also affordable (I like very much Orcad Capture for schematic capture - so easy to work with). Did you try Kicad ? it is also open-source and unlike gEDA there is a version for Windows.

Petr
 
HS3 said:
Converting TAN to angle in order to get SIN and COS is not the best way to do it because you need more calculation and will get higher error.
This is better
SIN=SQRT(1/(1+1/M^2))
COS=SQRT(1/(1+M^2))

Just got an email from the forum, sorry for not replying sooner. Thanks very much for your input. The way that you suggest is indeed better, thanks.

petrv said:
Sick of Eagle ? I can see why :D but I am still using it - I don't know about anything better that is also affordable (I like very much Orcad Capture for schematic capture - so easy to work with). Did you try Kicad ? it is also open-source and unlike gEDA there is a version for Windows.

Petr
I cant agree more. though Eagle has actually put me off electronics at the moment.
I seem to be a very single minded induvidual. I can only seem to be interested in one thing at any one time. Then ill start doing something else, and that something else is a replacement for eagle. Ill probably get sidetracked in about a month or two though!

I think ive tried just about all of the bad bunch of packages.
I have heard good things about orcad (my uni uses it, for example) but its not for me. I cant even remember all the reasons why i didnt like it, but i think one of the reasons was that it consists of about 10 seperate programs, and another was the slightly dated feel of the UI.
I think that this separate program idea is shite, and is probably a throw back to days gone by.

Here are my biggest problems with eagle:

Visual artefacts pollute the screen a lot of the time, requiring user to zoom in/out to remove them. It would appear that the makers of Eagle, never fully understood Win32API Invalidate method!

The stupid wrench tool. Why group so many options under one roof?

The component search dialog, which is horrendous.

Not enough autonomy. My program will make naming nets, etc easier, and will (hopefully) bring many new innovations to the humble schem capture and pcb editor package market.

Ive decided not to join an open source project myself, as I have a very clear idea of what I want from my program, not to mention that the encapsulated components that Im creating will come in handy as the building blocks for many future projects.

So far, i have completed a large chunk of the vector graphics class that is at the heart of the pcb and schem capture.

Now Im finally free to start on the meat of the application. the electronic specific parts.

Depending on the quality, and stability of the application (which is quite good so far!) and also If i receive enough interest, I may sell the program at a very reasonable price (something aimed at the hobbyist).

My original thoughts were to create a freeware package, but that’s gone out the window, now that I’ve realised how much work (not to mention time) is needed to complete the project to a professional standard.

When my project is nearing a more completed state, I will purchase some web space, and distribute a beta test:) .
 
Last edited:
Yes this lack of auto-redraw is really stupid (even a simple double-buffering algorithm would fix that) but you do not need to zoom in and out, just press F2
:) or in the layout editor you can also click the Ratsnest icon which will also cause a redraw.

Petr
 
Also another thing about eagle; it seems to "forget" about some connections when creating pcb air wires. I have created entire boards and relied on eagle to connect air wires to everything that should be connected, and only when id etched and started to solder did i realise that some things werent connected.

I need something a bit more reliable. And whats the point of the schem capture if it doesnt allways translate properly into airwires?
 
HerbertMunch said:
The stupid wrench tool. Why group so many options under one roof?

I use v.4.14. Tried the new beta and didn't like that aspect either.

Also another thing about eagle; it seems to "forget" about some connections when creating pcb air wires.

Do you run ERC on the schematic? The usual cause of "forgetting" an airwire is that the wire is not actually connected to the pin on the schematic. Only wires connected to pins at both ends show in the PCB. It may look like it is connected in the schematic, but in fact it may simply be overlaying the pin. ERC finds that and reports a non-connected pin.

Sorry to come so late. I read the original post and then didn't follow the thread. I hope these suggestions help. BTW, I did not like the EAGLE beta. There were some minor improvements, but I found many of the changes a disadvantage. I particularly didn't like the new select feature. John.
 
jpanhalt said:
I use v.4.14. Tried the new beta and didn't like that aspect either.



Do you run ERC on the schematic? The usual cause of "forgetting" an airwire is that the wire is not actually connected to the pin on the schematic. Only wires connected to pins at both ends show in the PCB. It may look like it is connected in the schematic, but in fact it may simply be overlaying the pin. ERC finds that and reports a non-connected pin.

Sorry to come so late. I read the original post and then didn't follow the thread. I hope these suggestions help. BTW, I did not like the EAGLE beta. There were some minor improvements, but I found many of the changes a disadvantage. I particularly didn't like the new select feature. John.

Hi john,
thanks for the advice.

I looked at the beta, and several updates pleased me, but I still think its crap.

As for the 'forgetting' problem, whether eagle is forgetting, or eagle is not joining the net to the pin properly, it results as the same same problem to me.
It highlights the very point that im trying to make. Eagle cannot be trusted 100% (more like 33.3% trust:) ).

Im aiming to make a program that is trustworthy, and that includes functionallity that makes the designers life easier.
IMO the end user should not have to double check the output from the program, it should just be right, first time.

Eagle should include some type of snap command that allows nets to be snapped to the pins, and then the problem would not occur.
It really hurts when you've got to the drilling or even the soldering stage, only to find that Eagle has let you down.

I have vowed not to do anything electronic until my program is ready, I have seen enough of eagle to a last a lifetime.
Dont know if ill be able hold out until completion though.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top