Linking borders of geometric figures - android

I'm creating an Android app which simulates petri nets. I'm representing place by circle and transition by square and I'm connecting those views by arc (it's just the name from petri nets for my purpose it's just a straight line) and here's the problem I'm facing, I know how to connect the centre point of those views but i don't know how to connect the border of circle and border of square, look at the image it should explain everything:
In my app I know if I'm pointing a place (circle) or transition (square), I also know the dimension of those views and it's coordinates, can you suggest me any start point for writing an algorithm which will connect borders of those two shapes and draw the arrow at the end of the line? Thanks in advance

You can make a method that takes in an angle and returns the point on the boundary at that angle from the center. This involves a little trigonometry, and cases for the square. To draw a line between the boundaries of two shapes, determine the angle of the difference vector atan2(difference in ys, difference in xs). Choose the point on the boundary with that angle. (This chooses the point that is on the line segment connecting the centers. You can change this if you want.) Connect the two points you get with a line, and add the arrow's head.

Related

Android Sceneform Plane Detection and their angles

I am trying to develop an Android app which is trying to draw a perfect line directly in front of me. My reference point is my phone, which means that the line has to parallel to my phone's left side.
I have following issues:
I am using Sceneform, so there is no "onSurfaceCreated" callback.(?)
I assume that the white-dots shows the surface. But, then I think if there is a detected surface then I can place a Shape on it. But is can not happen sometimes. And sometimes, I can place a Shape even if there are no visible white-dots.
When I try to draw a line between the points (0,0,0) to (1,0,0), it is not always parallel to the left side of my phone. I assume that the reason of this is related with the following fact :
angle between the left-bottom corner of the detected surface and the left-top corner is not zero. (If we consider the coordinate system as follows : phone's left side is y-axis, bottom is the x-axis.)And this angle changes each time I reopen the app.
These are more theory questions than the implementation. So, I need someone to prove or disprove, or give me guideline.
1) There isn't method like onSurfaceCreated.
2) Not all the detected planes are covered with white-dots. Is is intended because if all the detected planes are rendered with white-dots, it would confuse the users
3) When you talk about the points(0,0,0) and (1,0,0), is it world position or local position? Whether it is world position or local position, you can not draw a line parallel to your left side of phone in the way you approach.

convex path - how to?

Could someone explain me how convex path is calculated? I need to draw some cubic and additionally some lines but then path is shown as non convex. However when I leave only lines or just cubic it is then convex. The problem is that I need some non regular shaped background and need Convex path for shadow outline but can't get how I could connect drawing cubic with some lines to make convex path if it is even possible
A path is convex if it has a single contour, and only ever curves in a single direction.
Convex means it keeps bending / rotating in one direction, and one direction only. You really have to make sure that all your angles and curves add up. If your curve connects to a line it has to have the same angle or be "more convex", I hope the following 2 images will clear this up.
The picture below is not convex. That's also likely your problem. The line connects to a curve, but the curve has a different angle than the line and it will change the direction where it connects. See where the line goes down but instead of continuing the downwards-motion it suddenly goes up again. Instead of keeping one direction it will change for a moment where line and curve meet.
The above Image is exaggerated for clarity, but even small errors in the connection between the line and curve will trigger an error.
The next line connects to a curve with a steeper angle. This is convex and won't be a problem. See how the whole contour keeps a single motion in one direction, depending in which direction you follow it it keeps turning left/right.
I answered because I was facing a similar issue recently and I feel your pain. I recommend pen and paper to double and triple check the math and to use a small epsilon value to account for rounding errors etc... You really have to nail the math, because if your line and curve connection is just off by very little it will throw that exception.
Sorry for my bad paint skills

Android Canvas: Draw line with padding for extended touch/click area

Well I`m trying to find solution to a small problem.
I have multiple points on a canvas and have to connect them with a straight line. So exactly one incoming or outgoing connection per point. I have the 2 points for a line.
It all works with canvas.drawline(...) method. But now i want to be able to detect if a there was a click/touch event on a particular line within the line + padding area.
As line is drawn inside a rectangular bounding box its size varies based on the length and frequently overlaps with other bounding boxes. So considering touch within the bounding box is completely dumb i guess.
Can someone please give me some input in this direction?
Thanks a lot!
You can calculate perpendicular distance of the touch from the line.If the distance is within some range(in your case padding size) you consider as touch event on the line.
To calculate perpendicular distance use this formula refer-Shortest distance between a point and a line segment

Cut region out of intersecting lines on Android canvas

I have an Android canvas on which I'm drawing a series of lines to represent a hexagonal game board. The hexagon is subdivided with several intersecting interior lines.
I'm trying to figure out how to "cut out" a smaller hexagon from the center of the main hexagon, similar to this image: http://www.dcc.fc.up.pt/~pbv/stuff/hstzaar/hstzaar.png.
Is it possible to position a polygon over the intersecting lines and take the "difference" of the shapes, such that the lines underneath are modified to end at the polygon edges?
It might be sufficient to simply place an opaque polygon on top of the board center, but I was curious if it was possible to actually modify the underlying lines.
Since there are only 3 interior lines that run through the center of the hexagon, it's actually easier to draw each of them in two segments rather than try to cut them out later.
I'd still be interested to know if my original question was possible, but I solved the problem for now.

Drawing a circle in openGL for android

So I'd like to be able to draw a circle where I can specify the amount of circle drawn as shown in the following diagram.
AS an opengl newbie I'm not really sure how to approach this.. I've previously drawn full circles using GL_TRIANGLE_FAN
You already know how to draw a circle using a triangle fan. Now you just have to calculate the angles of the cutoff corners, use those as the beginning and end of the arc and place the hub of the triangle fan at the middle of the cutoff edge.
you could use a glScissor test to cut off the parts of the circle that you don't want.
http://www.khronos.org/opengles/sdk/1.1/docs/man/glScissor.xml

Categories

Resources