Straight Line Equation between two points - line

I need to paint the line which links two points.
I am doing it, in Java. I receive two points as parameters and I have to calculate if the straight line between them, is inside the black figure.
I developed my own solution using the straight line equation, but my results are different than using the "professional" programs (such as GIMP or even MS Paint).
Here is a example of what I want:
alt text http://img411.imageshack.us/img411/788/img1q.png
But my algorithm does this:
alt text http://img267.imageshack.us/img267/1908/img2d.png
*The green point is out of the figure and this is not possible.
Any ideas? Anyone know which code is been using for this, in "professional" apps?
Thanks!
Daniel.
EDIT: Images

It looks like you are truncating instead of rounding to the nearest pixel. Difficult to see on those small black ink splotches. Could you post the code?

"Professional" programs most likely use Bresenham's line algorithm.

Look at Bresenham's line drawing algorithm

Straignt lines are drawn using Bresenham's algorithm usually. I didn't get your point about green point being out of the figure - there's clipping to not waste time drawing outside the visible area.

Related

How to draw a colored circle around a part of an image with gimp?

The question is very simple. I just want to draw a simple circle around some part of an image with mouse. Not a fancy circle. It can be not at all a complete circle. I just want to circle around some part of an image to make it stand out inside the image.
As simple as this task is, I did not find any solution on google as it always proposes me very complex tasks like how to draw a circle and the like, which are not at all what I want. The problem is that Gimp is very powerful and so non-intuitive for very simple use cases. Any help will be appreciated as it will free me of doing all these changes under windows on another computer and sending the images via email and etc.
Quickest:
Make a circle selection with the Ellipse select tool (you can constrain it to a circle by depressing the Shift key after you start dragging).
Edit > Stroke selection (use preferably "Line" mode, that will also allow you to make a dotted line).
This said, to annotate images there are better alternatives.

White Border on Photoshop Text

I am trying to match the "teletext holidays" in the image below (with the white bits connecting all the letters:
I have achieved the following by going to the layers section, right-clicking the text layer, and select “Blending Options.” Then marking the checkbox next to “Stroke.”
Any hints or tips to point me in the correct direction would be appreciated. I appreciate moving the letters within the font closer together will help so will work on that now.
Any help appreciated.
Update:
Made the letters appear closer together. However, using stroke is making the black letters "shrink" in size so think a different solution is required. Thoughts?
With regard to that final image and the black letters appearing smaller. When applying the stroke, tick to indicate that it should be outside and not center or inside
And with helping to ensure that the white parts do meet.... Hmm... Well. Difficult to do the horiztonal stroke without it also applying vertically.
I would agree with others that Illustrator would be better but in Photoshop I might try to duplicate the text, make it all white, put it on the layer behind your main text and manually create a horizontal white pattern.
^ I really hope somebody has a better idea for that last bit though.
Alan,
I would like to help you with this issue. First of all your reference design is designed in adobe illustrator not in photoshop because there is some limitation in photoshop for the stroke feature.
So I would like to suggest you design it in adobe illustrator and not waste your valuable time in photoshop for your desired output.
If you need more help regarding it feel free to contact me at niravmistrydata#gmail.com.
Thank you,
Nirav Mistry

Labview : Attaching caption or label on lines in waveform graph

White, red, and green lines are some levels, according to a criterion, and blue line is measured spectrum, in upper picture.
Now, I want to attach the names of the lines, corresponding to levels, on the right end of lines.
The below picture is what I expect.
I couldn't find any plot property for these work.
Could anyone help me?
Thanks in advance.
You can use the Annotation List property to set annotations at specific points in the graph and I believe also link them to plots.
I have no practical experience with it, so I'm not familiar with all it can do. It might also give you the ability to manipulate specific annotations, etc. Play with it and see.
Here is the solution for the problem: https://lavag.org/topic/17756-xy-graph-programmatically-add-point-labels/
It uses Annotation List property as Yair told already.

SQL Server 2012 Spatial Data Type

I am trying to draw arrows. I know how to draw lines which takes me half way there but I want the tip to have a small triangle just like an arrow. However even when I use a triangle as a point, obviously it does not always point towards the direction of the line and might sometimes produce weird looking arrows.
I would like to draw the passes a player makes on a soccer field. I do that using LINESTRING and 4 coordinates I have in a table in my database. I use the xFrom, yFrom, xTo and yTo coordinates and I manage to draw lines. However I would like to have the tip of the line to show as an arrow but I found nothing in Google or in SQL documentation.
I would like to use SSRS and not any other graphics vector program because its simpler and its incorporated easily in my overall report.
Anyone can suggest a way of turning a line into an arrow?
Thanks
Okay, first off I'd like to preface this answer with the statement that using SQL Server and Reporting Services as a graphics tool is asking for trouble. This is by far, not what it was meant for.
With that being said, I believe this would work. You will need to spend some time studying, though. When manipulating images, you have several operations that you can perform. (Like Rotating, skewing, resizing, etc.) The mathematics behind these operations can be performed using matrix algebra. What you will need to do is look at the line you have created. It has a slope. If you picture that line superimposed upon X and Y axes, you can see that there is an angle between the line and the Y axis. (Assumes that the triagle's base rests upon the X axis.) That angle is the angle that you will want to rotate your triangle that you're using as the tip of the arrow. That should fix your problem. You could create a formula to do the calculations. (If the formula engine is robust enough to handle matrix algebra.)
Here are a couple of pages that give you the basics of how to rotate an image.
http://datagenetics.com/blog/august32013/index.html
http://www.fastgraph.com/makegames/3drotation/
Good luck!

draw outline for some connected lines

I have some lines that are connected at various points. I want to draw the outline of these lines and I also want to deal with the extra lines at the connection points.
I have seen two similar questions in this website: Here and here
I have handled the normal cases by offsetting the Centerlines and then changing the start and end points of the lines.
but I haven't been able to deal with special cases when the points are near each other.
Unfortunately, my reputation is low I couldn't post images to explain this better.
I'm coding in Visual Basic .net and I'm writing for Autocad, but any advice will be very useful to me.
most problem cases are solved by translation vectors intersection check
black is the original line/curve whatever ...
gray is translation vector (normal to black and size = outline distance)
blue is outline
if the translation vectors not intersect then it is most likely all OK but if they do then just do something like this:
cut off these points from outline
or create some singular point from these intersections
it is more tricky but can avoid some problem cases from bullet #1
Also sometimes help if there is bigger density of control points
Hope it helps a little...